master
 1import type { RehypePlugin } from '@astrojs/markdown-remark';
 2import type { ElementContent } from 'hast';
 3import { visit } from 'unist-util-visit';
 4
 5export const rehypeWrapTables: RehypePlugin = function () {
 6  return (tree) => {
 7    visit(tree, 'element', (node, index, parent) => {
 8      if (node.tagName === 'table' && parent && typeof index === 'number') {
 9        const wrapper = {
10          type: 'element',
11          tagName: 'div',
12          properties: { class: 'overflow-auto' },
13          children: [node],
14        };
15        parent.children[index] = wrapper as ElementContent;
16      }
17    });
18  };
19};