MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / visit

Function visit

apps/docs/astro.config.mjs:16–47  ·  view source on GitHub ↗
(node, parent, index)

Source from the content-addressed store, hash-verified

14function rehypeAccessibleTables() {
15 return (tree) => {
16 const visit = (node, parent, index) => {
17 if (!node || typeof node !== "object") return;
18 if (
19 node.type === "element" &&
20 node.tagName === "table" &&
21 parent &&
22 !(
23 parent.type === "element" &&
24 parent.tagName === "div" &&
25 parent.properties?.role === "region"
26 )
27 ) {
28 const wrapper = {
29 type: "element",
30 tagName: "div",
31 properties: {
32 role: "region",
33 "aria-label": "Scrollable table",
34 tabIndex: 0,
35 className: ["bs-table-scroll"],
36 },
37 children: [node],
38 };
39 parent.children[index] = wrapper;
40 return;
41 }
42 if (Array.isArray(node.children)) {
43 for (let i = 0; i < node.children.length; i++) {
44 visit(node.children[i], node, i);
45 }
46 }
47 };
48 visit(tree, null, 0);
49 };
50}

Callers 1

rehypeAccessibleTablesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected