From 146f904866e30a14faafdf77af1246e54b50792d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Fri, 12 Jan 2024 01:22:06 +0100 Subject: [PATCH] chore: small tweaks --- .markdownlint-cli2.jsonc | 4 ++-- src/utils.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc index 3d46c8b..0b4e176 100644 --- a/.markdownlint-cli2.jsonc +++ b/.markdownlint-cli2.jsonc @@ -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/**"], diff --git a/src/utils.js b/src/utils.js index e0c7f5a..a2345ee 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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. @@ -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) } }