Skip to content

Commit 415557c

Browse files
committed
Fix inferring IDs of headings with HTML
Closes GH-73.
1 parent 38da293 commit 415557c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/find/find-references.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export async function findReferences(ctx) {
7676
let id = String(props.name || props.id || data.id || '')
7777

7878
if (!id && node.type === 'heading') {
79-
id = slugs.slug(toString(node, {includeImageAlt: false}))
79+
id = slugs.slug(
80+
toString(node, {includeImageAlt: false, includeHtml: false})
81+
)
8082
}
8183

8284
if (id) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/mdast": "^3.0.0",
5050
"github-slugger": "^2.0.0",
5151
"hosted-git-info": "^5.0.0",
52-
"mdast-util-to-string": "^3.0.0",
52+
"mdast-util-to-string": "^3.2.0",
5353
"propose": "0.0.5",
5454
"to-vfile": "^7.0.0",
5555
"trough": "^2.0.0",

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ test('remark-validate-links', async (t) => {
7676
'should support landmarks and references to prototypal values'
7777
)
7878

79+
const fileHtml = await remark()
80+
.use(links)
81+
.use(sort)
82+
.process('# a <!-- b --> c\n# a <!-- b -->\n# a\n[](#a--c) [](#a-), [](#a)')
83+
84+
t.deepEqual(
85+
fileHtml.messages.map(String),
86+
[],
87+
'should slug headings with HTML correctly'
88+
)
89+
7990
let {stderr} = await exec(
8091
[
8192
bin,

0 commit comments

Comments
 (0)