diff --git a/packages/md/src/plugins/heading-extract.ts b/packages/md/src/plugins/heading-extract.ts deleted file mode 100644 index aa8f4989b..000000000 --- a/packages/md/src/plugins/heading-extract.ts +++ /dev/null @@ -1,39 +0,0 @@ -import type { RenderOptions, Token } from 'markdown-exit'; -import type MarkdownExit from 'markdown-exit'; - -export type HeadingData = Readonly<{ - depth: number; - slug: string; - text: string; -}>; - -type MarkdownEnv = Record & { - headings?: Array; -}; - -/** - * Extracts heading metadata into env.headings during rendering. - * Ported from VitePress headersPlugin. - */ -export function headingExtractPlugin(md: MarkdownExit): void { - const render = md.renderer.render.bind(md.renderer); - md.renderer.render = (tokens: Array, options: RenderOptions, env: MarkdownEnv = {}) => { - env.headings = []; - for (let tokenIndex = 0; tokenIndex < tokens.length; tokenIndex++) { - const token = tokens[tokenIndex]; - if (token.type === 'heading_open') { - const depth = Number(token.tag.slice(1)); - const slug = token.attrGet?.('id') ?? ''; - const inline = tokens[tokenIndex + 1]; - const text = ( - inline?.children - ?.filter((child) => child.type === 'text' || child.type === 'code_inline') - .map((child) => child.content) - .join('') ?? '' - ).trim(); - env.headings.push({ depth, slug, text }); - } - } - return render(tokens, options, env); - }; -}