summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/src/rehype-collect-headings.ts
blob: a51e8e9f02d8ceaebd4518d5c37294f41dc2e046 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
import type { VFile } from 'vfile';
import { jsToTreeNode } from './utils.js';

export function rehypeInjectHeadingsExport() {
	return function (tree: any, file: VFile) {
		const headings = file.data.astro?.headings ?? [];
		tree.children.unshift(
			jsToTreeNode(`export function getHeadings() { return ${JSON.stringify(headings)} }`),
		);
	};
}