mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01: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
|
|
@ -4421,10 +4421,15 @@ module.exports = {
|
||||||
"description": "Link fragments should be valid",
|
"description": "Link fragments should be valid",
|
||||||
"tags": ["links"],
|
"tags": ["links"],
|
||||||
"function": function MD051(params, onError) {
|
"function": function MD051(params, onError) {
|
||||||
var fragments = new Set();
|
var fragments = new Map();
|
||||||
// Process headings
|
// Process headings
|
||||||
forEachHeading(params, function (heading, content, inline) {
|
forEachHeading(params, function (heading, content, inline) {
|
||||||
fragments.add(convertHeadingToHTMLFragment(inline));
|
var fragment = convertHeadingToHTMLFragment(inline);
|
||||||
|
var count = fragments.get(fragment) || 0;
|
||||||
|
if (count) {
|
||||||
|
fragments.set("".concat(fragment, "-").concat(count), 0);
|
||||||
|
}
|
||||||
|
fragments.set(fragment, count + 1);
|
||||||
});
|
});
|
||||||
// Process HTML anchors
|
// Process HTML anchors
|
||||||
var processHtmlToken = function (token) {
|
var processHtmlToken = function (token) {
|
||||||
|
|
@ -4434,7 +4439,7 @@ module.exports = {
|
||||||
if (element.toLowerCase() === "a") {
|
if (element.toLowerCase() === "a") {
|
||||||
var idMatch = identifierRe.exec(tag);
|
var idMatch = identifierRe.exec(tag);
|
||||||
if (idMatch) {
|
if (idMatch) {
|
||||||
fragments.add("#".concat(idMatch[1]));
|
fragments.set("#".concat(idMatch[1]), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
lib/md051.js
11
lib/md051.js
|
|
@ -37,10 +37,15 @@ module.exports = {
|
||||||
"description": "Link fragments should be valid",
|
"description": "Link fragments should be valid",
|
||||||
"tags": [ "links" ],
|
"tags": [ "links" ],
|
||||||
"function": function MD051(params, onError) {
|
"function": function MD051(params, onError) {
|
||||||
const fragments = new Set();
|
const fragments = new Map();
|
||||||
// Process headings
|
// Process headings
|
||||||
forEachHeading(params, (heading, content, inline) => {
|
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
|
// Process HTML anchors
|
||||||
const processHtmlToken = (token) => {
|
const processHtmlToken = (token) => {
|
||||||
|
|
@ -50,7 +55,7 @@ module.exports = {
|
||||||
if (element.toLowerCase() === "a") {
|
if (element.toLowerCase() === "a") {
|
||||||
const idMatch = identifierRe.exec(tag);
|
const idMatch = identifierRe.exec(tag);
|
||||||
if (idMatch) {
|
if (idMatch) {
|
||||||
fragments.add(`#${idMatch[1]}`);
|
fragments.set(`#${idMatch[1]}`, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@
|
||||||
|
|
||||||
[Valid](#valid-setext-heading)
|
[Valid](#valid-setext-heading)
|
||||||
|
|
||||||
|
[Valid](#valid-repeated-heading)
|
||||||
|
|
||||||
|
[Valid](#valid-repeated-heading-1)
|
||||||
|
|
||||||
|
[Valid](#valid-repeated-heading-2)
|
||||||
|
|
||||||
[Valid](#namedlink)
|
[Valid](#namedlink)
|
||||||
|
|
||||||
[Valid](#idlink)
|
[Valid](#idlink)
|
||||||
|
|
@ -77,6 +83,16 @@ Valid Setext Heading
|
||||||
|
|
||||||
Text
|
Text
|
||||||
|
|
||||||
|
### Valid Repeated Heading
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
### Valid Repeated Heading
|
||||||
|
|
||||||
|
Text
|
||||||
|
|
||||||
|
### Valid Repeated Heading
|
||||||
|
|
||||||
<a name="namedlink"></a>
|
<a name="namedlink"></a>
|
||||||
|
|
||||||
<a id = idlink></a>
|
<a id = idlink></a>
|
||||||
|
|
@ -89,7 +105,9 @@ Text
|
||||||
|
|
||||||
## Invalid Fragments
|
## Invalid Fragments
|
||||||
|
|
||||||
[Inalid](#valid-heading-2004-) {MD051}
|
[Invalid](#valid-heading-2004-) {MD051}
|
||||||
|
|
||||||
|
[Invalid](#valid-repeated-heading-3) {MD051}
|
||||||
|
|
||||||
[Invalid](#invalid-fragment) {MD051}
|
[Invalid](#invalid-fragment) {MD051}
|
||||||
|
|
||||||
|
|
@ -104,5 +122,6 @@ Text
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"emphasis-style": false,
|
"emphasis-style": false,
|
||||||
"heading-style": false,
|
"heading-style": false,
|
||||||
|
"no-duplicate-heading": false,
|
||||||
"no-inline-html": false
|
"no-inline-html": false
|
||||||
} -->
|
} -->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue