Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 10c25f9

Browse files
committed
fix toc slugs
1 parent 100adaa commit 10c25f9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/mdx/rehype.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ function rehypeSlugify() {
2626
let slugify = slugifyWithCounter()
2727
visit(tree, 'element', (node) => {
2828
if (ALLOWED_TAGS.includes(node.tagName) && !node.properties.id) {
29-
node.properties.id = slugify(toString(node))
29+
node.properties.id = slugify(toString(node), {
30+
decamelize: false,
31+
customReplacements: [['’', '']],
32+
})
3033
}
3134
})
3235
}

src/mdx/remark-toc-headings.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { visit } from 'unist-util-visit'
22
import { toString } from 'mdast-util-to-string'
33
import { remark } from 'remark'
4-
import slugify from 'slugify'
4+
import { slugifyWithCounter } from '@sindresorhus/slugify'
55

66
/**
77
* Extracts TOC headings from markdown file and adds it to the file's data object.
88
*/
99
export const remarkTocHeadings =
1010
(includedDepths = [2]) =>
1111
() => {
12+
const slugify = slugifyWithCounter()
13+
1214
return (tree, file) => {
1315
const toc = []
1416
visit(tree, 'heading', (node) => {
@@ -20,8 +22,8 @@ export const remarkTocHeadings =
2022
url:
2123
'#' +
2224
slugify(textContent, {
23-
lower: true,
24-
strict: true,
25+
decamelize: false,
26+
customReplacements: [['’', '']],
2527
}),
2628
depth: node.depth,
2729
})

0 commit comments

Comments
 (0)