mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2024-11-04 18:21:31 +01:00
fix: fragments checking should work in other elements than only anchor (e.g: <div>)
This commit is contained in:
parent
a5deae599a
commit
747203c23b
16
src/utils.js
16
src/utils.js
@ -100,11 +100,11 @@ const anchorNameRe = getHtmlAttributeRe("name")
|
||||
const anchorIdRe = getHtmlAttributeRe("id")
|
||||
|
||||
/**
|
||||
* Gets the anchor HTML fragments from a Markdown string.
|
||||
* Gets the id or anchor name fragments from a Markdown string.
|
||||
* @param {string} content
|
||||
* @returns {string[]}
|
||||
*/
|
||||
const getMarkdownAnchorHTMLFragments = (content) => {
|
||||
const getMarkdownIdOrAnchorNameFragments = (content) => {
|
||||
const markdownIt = new MarkdownIt({ html: true })
|
||||
const tokens = markdownIt.parse(content, {})
|
||||
|
||||
@ -112,13 +112,6 @@ const getMarkdownAnchorHTMLFragments = (content) => {
|
||||
const result = []
|
||||
|
||||
for (const token of tokens) {
|
||||
if (token.type === "inline") {
|
||||
if (!token.children) {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const child of token.children) {
|
||||
if (child.type === "html_inline") {
|
||||
const anchorMatch =
|
||||
anchorIdRe.exec(token.content) || anchorNameRe.exec(token.content)
|
||||
if (!anchorMatch || anchorMatch.length === 0) {
|
||||
@ -135,9 +128,6 @@ const getMarkdownAnchorHTMLFragments = (content) => {
|
||||
result.push(anchorHTMLFragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
@ -146,5 +136,5 @@ module.exports = {
|
||||
filterTokens,
|
||||
convertHeadingToHTMLFragment,
|
||||
getMarkdownHeadings,
|
||||
getMarkdownAnchorHTMLFragments,
|
||||
getMarkdownAnchorHTMLFragments: getMarkdownIdOrAnchorNameFragments,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user