From 415557c15bbf6889e598b50fc885e6c22c9b654f Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 3 Apr 2023 17:33:33 +0200 Subject: [PATCH] Fix inferring IDs of headings with HTML Closes GH-73. --- lib/find/find-references.js | 4 +++- package.json | 2 +- test/index.js | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/find/find-references.js b/lib/find/find-references.js index c5e0d35..953dec3 100644 --- a/lib/find/find-references.js +++ b/lib/find/find-references.js @@ -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) { diff --git a/package.json b/package.json index f7be06b..87e22a3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/index.js b/test/index.js index de50db3..fa0d0d3 100644 --- a/test/index.js +++ b/test/index.js @@ -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 c\n# a \n# a\n[](#a--c) [](#a-), [](#a)') + + t.deepEqual( + fileHtml.messages.map(String), + [], + 'should slug headings with HTML correctly' + ) + let {stderr} = await exec( [ bin,