From 181d704e94bde2ad43c4d9c90bbe5a6383536c8e Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Mon, 3 Jun 2024 16:16:22 +0200 Subject: [PATCH] add support and tests for single quotes --- index.js | 4 ++-- test/hash-links.md | 8 +++++++- test/markdown-link-check.test.js | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 98c76ab..aad6ea3 100644 --- a/index.js +++ b/index.js @@ -56,8 +56,8 @@ function extractHtmlSections(markdown) { // remove single line code (if not escaped with "\") .replace(/(?[^\s]+).*?id="(?[^"]*?)".*?>/gmi; - const regexAName = /[^"]*?)".*?>/gmi; + const regexAllId = /<(?[^\s]+).*?id=["'](?[^"']*?)["'].*?>/gmi; + const regexAName = /[^"']*?)["'].*?>/gmi; const sections = [] .concat(Array.from(markdown.matchAll(regexAllId), (match) => match.groups.id)) diff --git a/test/hash-links.md b/test/hash-links.md index e9e53de..33e3d70 100644 --- a/test/hash-links.md +++ b/test/hash-links.md @@ -2,9 +2,11 @@ - + + +
@@ -39,6 +41,10 @@ There is an anchor named with `id` [Tomato](#tomato_id). There is an anchor named with `name` [Tomato](#tomato_name). +There is an anchor named with `id` [Tomato in single quote](#tomato_id_single_quote). + +There is an anchor named with `name` [Tomato in single quote](#tomato_name_single_quote). + There is an anchor in code [Tomato in code](#tomato_code). There is an anchor in escaped code [Tomato in escaped backticks](#tomato_escaped_backticks). diff --git a/test/markdown-link-check.test.js b/test/markdown-link-check.test.js index eb77212..2d043f5 100644 --- a/test/markdown-link-check.test.js +++ b/test/markdown-link-check.test.js @@ -379,6 +379,8 @@ describe('markdown-link-check', function () { { link: '#potato', statusCode: 404, err: null, status: 'dead' }, { link: '#tomato_id', statusCode: 200, err: null, status: 'alive' }, { link: '#tomato_name', statusCode: 200, err: null, status: 'alive' }, + { link: '#tomato_id_single_quote', statusCode: 200, err: null, status: 'alive' }, + { link: '#tomato_name_single_quote', statusCode: 200, err: null, status: 'alive' }, { link: '#tomato_code', statusCode: 404, err: null, status: 'dead' }, { link: '#tomato_escaped_backticks', statusCode: 200, err: null, status: 'alive' }, { link: '#tomato_comment', statusCode: 404, err: null, status: 'dead' },