mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Add getHtmlAttributeRe helper for creating a RegExp to match an HTML attribute name/value.
This commit is contained in:
parent
531e58ed9a
commit
06466905a5
4 changed files with 36 additions and 15 deletions
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, addErrorDetailIf } = require("../helpers");
|
||||
const { addError, addErrorDetailIf, getHtmlAttributeRe } =
|
||||
require("../helpers");
|
||||
const { filterByPredicate, filterByTypes, getHtmlTagInfo } =
|
||||
require("../helpers/micromark.cjs");
|
||||
|
||||
// Regular expression for identifying HTML anchor names
|
||||
const idRe = /\sid\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||
const nameRe = /\sname\s*=\s*['"]?([^'"\s>]+)/iu;
|
||||
const idRe = getHtmlAttributeRe("id");
|
||||
const nameRe = getHtmlAttributeRe("name");
|
||||
const anchorRe = /\{(#[a-z\d]+(?:[-_][a-z\d]+)*)\}/gu;
|
||||
|
||||
// Sets for filtering heading tokens during conversion
|
||||
|
|
@ -101,7 +102,7 @@ module.exports = {
|
|||
if (htmlTagInfo && !htmlTagInfo.close) {
|
||||
const anchorMatch = idRe.exec(token.text) ||
|
||||
(htmlTagInfo.name.toLowerCase() === "a" && nameRe.exec(token.text));
|
||||
if (anchorMatch) {
|
||||
if (anchorMatch && anchorMatch.length > 0) {
|
||||
fragments.set(`#${anchorMatch[1]}`, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue