summaryrefslogtreecommitdiff
path: root/packages/markdown/remark/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/markdown/remark/src/index.ts')
-rw-r--r--packages/markdown/remark/src/index.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts
index c64bdac0e..6d69bcd20 100644
--- a/packages/markdown/remark/src/index.ts
+++ b/packages/markdown/remark/src/index.ts
@@ -1,7 +1,7 @@
-import type { MarkdownRenderingOptions, MarkdownRenderingResult } from './types';
+import type { MarkdownRenderingOptions, MarkdownRenderingResult, MarkdownVFile } from './types';
import { loadPlugins } from './load-plugins.js';
-import createCollectHeadings from './rehype-collect-headings.js';
+import { rehypeHeadingIds } from './rehype-collect-headings.js';
import rehypeEscape from './rehype-escape.js';
import rehypeExpressions from './rehype-expressions.js';
import rehypeIslands from './rehype-islands.js';
@@ -22,6 +22,7 @@ import markdownToHtml from 'remark-rehype';
import { unified } from 'unified';
import { VFile } from 'vfile';
+export { rehypeHeadingIds } from './rehype-collect-headings.js';
export * from './types.js';
export const DEFAULT_REMARK_PLUGINS = ['remark-gfm', 'remark-smartypants'];
@@ -44,7 +45,6 @@ export async function renderMarkdown(
} = opts;
const input = new VFile({ value: content, path: fileURL });
const scopedClassName = opts.$?.scopedClassName;
- const { headings, rehypeCollectHeadings } = createCollectHeadings();
let parser = unified()
.use(markdown)
@@ -99,12 +99,12 @@ export async function renderMarkdown(
parser
.use(
isAstroFlavoredMd
- ? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeCollectHeadings]
- : [rehypeCollectHeadings, rehypeRaw]
+ ? [rehypeJsx, rehypeExpressions, rehypeEscape, rehypeIslands, rehypeHeadingIds]
+ : [rehypeHeadingIds, rehypeRaw]
)
.use(rehypeStringify, { allowDangerousHtml: true });
- let vfile: VFile;
+ let vfile: MarkdownVFile;
try {
vfile = await parser.process(input);
} catch (err) {
@@ -116,6 +116,7 @@ export async function renderMarkdown(
throw err;
}
+ const headings = vfile?.data.__astroHeadings || [];
return {
metadata: { headings, source: content, html: String(vfile.value) },
code: String(vfile.value),