mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add support for named heading fragments as supported by some platforms (fixes #830).
This commit is contained in:
parent
3dcb66cac5
commit
7a794192ca
8 changed files with 295 additions and 18 deletions
|
@ -8,6 +8,7 @@ const { addError, addErrorDetailIf, escapeForRegExp, filterTokens,
|
|||
// Regular expression for identifying HTML anchor names
|
||||
const idRe = /\sid\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||
const nameRe = /\sname\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||
const anchorRe = /\{(#[a-z\d]+(?:[-_][a-z\d]+)*)\}/gu;
|
||||
|
||||
/**
|
||||
* Converts a Markdown heading into an HTML fragment according to the rules
|
||||
|
@ -50,6 +51,13 @@ module.exports = {
|
|||
fragments.set(`${fragment}-${count}`, 0);
|
||||
}
|
||||
fragments.set(fragment, count + 1);
|
||||
let match = null;
|
||||
while ((match = anchorRe.exec(content)) !== null) {
|
||||
const [ , anchor ] = match;
|
||||
if (!fragments.has(anchor)) {
|
||||
fragments.set(anchor, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
// Process HTML anchors
|
||||
const processHtmlToken = (token) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue