summaryrefslogtreecommitdiff
path: root/packages/markdown-support/src/rehype-collect-headers.ts
diff options
context:
space:
mode:
authorGravatar Pavel Mineev <pavel@mineev.me> 2021-07-01 19:55:22 +0300
committerGravatar GitHub <noreply@github.com> 2021-07-01 11:55:22 -0500
commitd3969436dcbe40a3d41a036ff7c2761aed176109 (patch)
tree5b79d1ce306566bc53a71e2fe2e5b494adf20904 /packages/markdown-support/src/rehype-collect-headers.ts
parente773771b917d1d11e8a5647ccdc2d44c903f1f4c (diff)
downloadastro-d3969436dcbe40a3d41a036ff7c2761aed176109.tar.gz
astro-d3969436dcbe40a3d41a036ff7c2761aed176109.tar.zst
astro-d3969436dcbe40a3d41a036ff7c2761aed176109.zip
Remark and rehype plugins (#562)
* remark plugins * remove unused dependency * enable codeblocks * backward compatibility with remark-code-titles * add support for rehype plugins * add proper types for plugins * fixes after review - connect plugins by name - make plugins configurable - connect gfm and footnotes if no plugins provided from config - add more plugins to example * update and rename example * add documentation for markdown plugins * chore: rename with-markdown-plugins example * chore: restructure dependencies * feat: add back smartypants, fix mdx expressions * chore: remove log * test: add markdown plugin tests * chore: add changeset * docs: update markdown doc Co-authored-by: Nate Moore <nate@skypack.dev>
Diffstat (limited to 'packages/markdown-support/src/rehype-collect-headers.ts')
-rw-r--r--packages/markdown-support/src/rehype-collect-headers.ts4
1 files changed, 3 insertions, 1 deletions
diff --git a/packages/markdown-support/src/rehype-collect-headers.ts b/packages/markdown-support/src/rehype-collect-headers.ts
index edfcd29bc..de9b78692 100644
--- a/packages/markdown-support/src/rehype-collect-headers.ts
+++ b/packages/markdown-support/src/rehype-collect-headers.ts
@@ -14,11 +14,13 @@ export default function createCollectHeaders() {
depth = Number.parseInt(depth);
let text = '';
+
visit(node, 'text', (child) => {
text += child.value;
});
- let slug = slugger.slug(text);
+ let slug = node.properties.id || slugger.slug(text);
+
node.properties = node.properties || {};
node.properties.id = slug;
headers.push({ depth, slug, text });