mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD051/link-fragments to support indexing of repated headings.
This commit is contained in:
parent
8c5f28c2f0
commit
152720f00e
3 changed files with 36 additions and 7 deletions
11
lib/md051.js
11
lib/md051.js
|
@ -37,10 +37,15 @@ module.exports = {
|
|||
"description": "Link fragments should be valid",
|
||||
"tags": [ "links" ],
|
||||
"function": function MD051(params, onError) {
|
||||
const fragments = new Set();
|
||||
const fragments = new Map();
|
||||
// Process headings
|
||||
forEachHeading(params, (heading, content, inline) => {
|
||||
fragments.add(convertHeadingToHTMLFragment(inline));
|
||||
const fragment = convertHeadingToHTMLFragment(inline);
|
||||
const count = fragments.get(fragment) || 0;
|
||||
if (count) {
|
||||
fragments.set(`${fragment}-${count}`, 0);
|
||||
}
|
||||
fragments.set(fragment, count + 1);
|
||||
});
|
||||
// Process HTML anchors
|
||||
const processHtmlToken = (token) => {
|
||||
|
@ -50,7 +55,7 @@ module.exports = {
|
|||
if (element.toLowerCase() === "a") {
|
||||
const idMatch = identifierRe.exec(tag);
|
||||
if (idMatch) {
|
||||
fragments.add(`#${idMatch[1]}`);
|
||||
fragments.set(`#${idMatch[1]}`, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue