| 102 | } |
| 103 | |
| 104 | export function getSections(node) { |
| 105 | let sections = []; |
| 106 | |
| 107 | for (let child of node.children ?? []) { |
| 108 | if (child.type === 'element' && child.tagName === 'h2') { |
| 109 | sections.push(`{ |
| 110 | title: ${JSON.stringify(toString(child))}, |
| 111 | id: ${JSON.stringify(child.properties.id)}, |
| 112 | ...${child.properties.annotation} |
| 113 | }`); |
| 114 | } else if (child.children) { |
| 115 | sections.push(...getSections(child)); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | return sections; |
| 120 | } |
| 121 | |
| 122 | export const rehypePlugins = [ |
| 123 | mdxAnnotations.rehype, |