From 844faf95fe39e3d3185db848a108c32c05739417 Mon Sep 17 00:00:00 2001 From: shulaoda <165626830+shulaoda@users.noreply.github.com> Date: Wed, 1 Jul 2026 07:34:19 +0800 Subject: [PATCH] chore(md): remove dead heading-extract plugin This removes packages/md/src/plugins/heading-extract.ts, the file that exported the headingExtractPlugin function and the HeadingData type. The module is dead code. headingExtractPlugin is never imported or registered anywhere in the monorepo, and HeadingData has no references. Heading and TOC extraction is already provided by tocPlugin, which is registered in compile.ts through markdown.use(tocPlugin), and by the local extractHeadings helpers in compile.ts and metadata.ts. The deleted file is a leftover from the original VitePress port that those implementations superseded. There is no behavior change. The file was not registered in compile.ts, was not re-exported from the package entry index.ts, and was not part of the package exports surface, so nothing observable changes. There are zero references to headingExtractPlugin and HeadingData across packages, docs, and playground, excluding dist. The void md package typechecks cleanly with tsgo. The net change removes one file and 39 lines. --- packages/md/src/plugins/heading-extract.ts | 39 ---------------------- 1 file changed, 39 deletions(-) delete mode 100644 packages/md/src/plugins/heading-extract.ts 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); - }; -}