Skip to content

Commit

Permalink
add support and tests for single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Jun 3, 2024
1 parent cb1cb61 commit 181d704
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ function extractHtmlSections(markdown) {
// remove single line code (if not escaped with "\")
.replace(/(?<!\\)`[\S\s]+?(?<!\\)`/gm, '');

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

const sections = []
.concat(Array.from(markdown.matchAll(regexAllId), (match) => match.groups.id))
Expand Down
8 changes: 7 additions & 1 deletion test/hash-links.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

<!-- markdownlint-disable MD033 -->
<a id="tomato_id"></a>

<a name="tomato_name"></a>

<a id='tomato_id_single_quote'></a>
<a name='tomato_name_single_quote'></a>

<div id="onion"></div>
<div id="onion_outer">
<div id="onion_inner"></div>
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 2 additions & 0 deletions test/markdown-link-check.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down

0 comments on commit 181d704

Please sign in to comment.