Skip to content

Commit

Permalink
Fix inferring IDs of headings with HTML
Browse files Browse the repository at this point in the history
Closes GH-73.
  • Loading branch information
wooorm committed Apr 3, 2023
1 parent 38da293 commit 415557c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/find/find-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export async function findReferences(ctx) {
let id = String(props.name || props.id || data.id || '')

if (!id && node.type === 'heading') {
id = slugs.slug(toString(node, {includeImageAlt: false}))
id = slugs.slug(
toString(node, {includeImageAlt: false, includeHtml: false})
)
}

if (id) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/mdast": "^3.0.0",
"github-slugger": "^2.0.0",
"hosted-git-info": "^5.0.0",
"mdast-util-to-string": "^3.0.0",
"mdast-util-to-string": "^3.2.0",
"propose": "0.0.5",
"to-vfile": "^7.0.0",
"trough": "^2.0.0",
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ test('remark-validate-links', async (t) => {
'should support landmarks and references to prototypal values'
)

const fileHtml = await remark()
.use(links)
.use(sort)
.process('# a <!-- b --> c\n# a <!-- b -->\n# a\n[](#a--c) [](#a-), [](#a)')

t.deepEqual(
fileHtml.messages.map(String),
[],
'should slug headings with HTML correctly'
)

let {stderr} = await exec(
[
bin,
Expand Down

0 comments on commit 415557c

Please sign in to comment.