mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2024-12-08 00:45:32 +01:00
chore: small tweaks
This commit is contained in:
parent
64396954e4
commit
146f904866
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"extends": "markdownlint/style/prettier",
|
"extends": "markdownlint/style/prettier",
|
||||||
"relative-links": true,
|
|
||||||
"default": true,
|
"default": true,
|
||||||
"MD033": false
|
"relative-links": true,
|
||||||
|
"no-inline-html": false
|
||||||
},
|
},
|
||||||
"globs": ["**/*.{md,mdx}"],
|
"globs": ["**/*.{md,mdx}"],
|
||||||
"ignores": ["**/node_modules", "**/test/fixtures/**"],
|
"ignores": ["**/node_modules", "**/test/fixtures/**"],
|
||||||
|
21
src/utils.js
21
src/utils.js
@ -77,8 +77,8 @@ const getMarkdownHeadings = (content) => {
|
|||||||
return headings
|
return headings
|
||||||
}
|
}
|
||||||
|
|
||||||
const anchorNameRe = getHtmlAttributeRe("name")
|
const nameHTMLAttributeRegex = getHtmlAttributeRe("name")
|
||||||
const anchorIdRe = getHtmlAttributeRe("id")
|
const idHTMLAttributeRegex = getHtmlAttributeRe("id")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the id or anchor name fragments from a Markdown string.
|
* Gets the id or anchor name fragments from a Markdown string.
|
||||||
@ -93,20 +93,21 @@ const getMarkdownIdOrAnchorNameFragments = (content) => {
|
|||||||
const result = []
|
const result = []
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
const anchorMatch =
|
const regexMatch =
|
||||||
anchorIdRe.exec(token.content) || anchorNameRe.exec(token.content)
|
idHTMLAttributeRegex.exec(token.content) ||
|
||||||
if (anchorMatch == null) {
|
nameHTMLAttributeRegex.exec(token.content)
|
||||||
|
if (regexMatch == null) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const anchorIdOrName = anchorMatch[1]
|
const idOrName = regexMatch[1]
|
||||||
if (anchorIdOrName == null || anchorIdOrName.length <= 0) {
|
if (idOrName == null || idOrName.length <= 0) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const anchorHTMLFragment = "#" + anchorIdOrName
|
const htmlFragment = "#" + idOrName
|
||||||
if (!result.includes(anchorHTMLFragment)) {
|
if (!result.includes(htmlFragment)) {
|
||||||
result.push(anchorHTMLFragment)
|
result.push(htmlFragment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user