Make all tables in markdown responsives to fix issue #295

This commit is contained in:
prototypa
2023-12-01 10:42:30 -05:00
parent 6576ea70ec
commit 0dc98a56f2
2 changed files with 27 additions and 1 deletions

View File

@ -9,3 +9,28 @@ export function readingTimeRemarkPlugin() {
file.data.astro.frontmatter.readingTime = readingTime;
};
}
export function responsiveTablesRehypePlugin() {
return function (tree) {
if (!tree.children) return;
for (let i = 0; i < tree.children.length; i++) {
const child = tree.children[i];
if (child.type === 'element' && child.tagName === 'table') {
const wrapper = {
type: 'element',
tagName: 'div',
properties: {
style: 'overflow:auto',
},
children: [child],
};
tree.children[i] = wrapper;
i++;
}
}
};
}