Skip to content

Commit 181d704

Browse files
committed
add support and tests for single quotes
1 parent cb1cb61 commit 181d704

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ function extractHtmlSections(markdown) {
5656
// remove single line code (if not escaped with "\")
5757
.replace(/(?<!\\)`[\S\s]+?(?<!\\)`/gm, '');
5858

59-
const regexAllId = /<(?<tag>[^\s]+).*?id="(?<id>[^"]*?)".*?>/gmi;
60-
const regexAName = /<a.*?name="(?<name>[^"]*?)".*?>/gmi;
59+
const regexAllId = /<(?<tag>[^\s]+).*?id=["'](?<id>[^"']*?)["'].*?>/gmi;
60+
const regexAName = /<a.*?name=["'](?<name>[^"']*?)["'].*?>/gmi;
6161

6262
const sections = []
6363
.concat(Array.from(markdown.matchAll(regexAllId), (match) => match.groups.id))

test/hash-links.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
<!-- markdownlint-disable MD033 -->
44
<a id="tomato_id"></a>
5-
65
<a name="tomato_name"></a>
76

7+
<a id='tomato_id_single_quote'></a>
8+
<a name='tomato_name_single_quote'></a>
9+
810
<div id="onion"></div>
911
<div id="onion_outer">
1012
<div id="onion_inner"></div>
@@ -39,6 +41,10 @@ There is an anchor named with `id` [Tomato](#tomato_id).
3941

4042
There is an anchor named with `name` [Tomato](#tomato_name).
4143

44+
There is an anchor named with `id` [Tomato in single quote](#tomato_id_single_quote).
45+
46+
There is an anchor named with `name` [Tomato in single quote](#tomato_name_single_quote).
47+
4248
There is an anchor in code [Tomato in code](#tomato_code).
4349

4450
There is an anchor in escaped code [Tomato in escaped backticks](#tomato_escaped_backticks).

test/markdown-link-check.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ describe('markdown-link-check', function () {
379379
{ link: '#potato', statusCode: 404, err: null, status: 'dead' },
380380
{ link: '#tomato_id', statusCode: 200, err: null, status: 'alive' },
381381
{ link: '#tomato_name', statusCode: 200, err: null, status: 'alive' },
382+
{ link: '#tomato_id_single_quote', statusCode: 200, err: null, status: 'alive' },
383+
{ link: '#tomato_name_single_quote', statusCode: 200, err: null, status: 'alive' },
382384
{ link: '#tomato_code', statusCode: 404, err: null, status: 'dead' },
383385
{ link: '#tomato_escaped_backticks', statusCode: 200, err: null, status: 'alive' },
384386
{ link: '#tomato_comment', statusCode: 404, err: null, status: 'dead' },

0 commit comments

Comments
 (0)