From 68f35ddc0b77085c40299ab9172dd4be0a19a3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20LUDWIG?= Date: Fri, 12 Jan 2024 00:10:00 +0100 Subject: [PATCH] fix: empty id fragment should be invalid --- src/index.js | 15 ++++++++++++++- src/utils.js | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index bde6243..1243d00 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,20 @@ const customRule = { continue } - if (type === "link_open" && url.hash !== "") { + if (type !== "link_open") { + continue + } + + if (url.hash.length <= 0) { + if (hrefSrc.includes("#")) { + onError({ + lineNumber, + detail: `${detail} should have a valid fragment identifier`, + }) + } + } + + if (url.hash.length > 0) { const fileContent = fs.readFileSync(url, { encoding: "utf8" }) const headings = getMarkdownHeadings(fileContent) const anchorHTMLFragments = diff --git a/src/utils.js b/src/utils.js index 8bbc01b..7ed20a3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,7 +119,7 @@ const getMarkdownIdOrAnchorNameFragments = (content) => { } const anchorIdOrName = anchorMatch[1] - if (anchorMatch[1] === undefined) { + if (anchorIdOrName === undefined) { continue }