Skip to content

Commit

Permalink
chore: small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
theoludwig committed Jan 12, 2024
1 parent 6439695 commit 146f904
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"config": {
"extends": "markdownlint/style/prettier",
"relative-links": true,
"default": true,
"MD033": false
"relative-links": true,
"no-inline-html": false
},
"globs": ["**/*.{md,mdx}"],
"ignores": ["**/node_modules", "**/test/fixtures/**"],
Expand Down
21 changes: 11 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ const getMarkdownHeadings = (content) => {
return headings
}

const anchorNameRe = getHtmlAttributeRe("name")
const anchorIdRe = getHtmlAttributeRe("id")
const nameHTMLAttributeRegex = getHtmlAttributeRe("name")
const idHTMLAttributeRegex = getHtmlAttributeRe("id")

/**
* Gets the id or anchor name fragments from a Markdown string.
Expand All @@ -93,20 +93,21 @@ const getMarkdownIdOrAnchorNameFragments = (content) => {
const result = []

for (const token of tokens) {
const anchorMatch =
anchorIdRe.exec(token.content) || anchorNameRe.exec(token.content)
if (anchorMatch == null) {
const regexMatch =
idHTMLAttributeRegex.exec(token.content) ||
nameHTMLAttributeRegex.exec(token.content)
if (regexMatch == null) {
continue
}

const anchorIdOrName = anchorMatch[1]
if (anchorIdOrName == null || anchorIdOrName.length <= 0) {
const idOrName = regexMatch[1]
if (idOrName == null || idOrName.length <= 0) {
continue
}

const anchorHTMLFragment = "#" + anchorIdOrName
if (!result.includes(anchorHTMLFragment)) {
result.push(anchorHTMLFragment)
const htmlFragment = "#" + idOrName
if (!result.includes(htmlFragment)) {
result.push(htmlFragment)
}
}

Expand Down

0 comments on commit 146f904

Please sign in to comment.