feat: html anchor support

This commit is contained in:
Igor Tsiglyar
2024-01-11 13:42:34 +00:00
committed by Théo LUDWIG
parent 9d2cc818d5
commit 24a0788d32
11 changed files with 123 additions and 11 deletions
+5
View File
@@ -7,6 +7,7 @@ const {
filterTokens,
convertHeadingToHTMLFragment,
getMarkdownHeadings,
getMarkdownAnchorHTMLFragments,
} = require("./utils.js")
/** @typedef {import('markdownlint').Rule} MarkdownLintRule */
@@ -63,6 +64,8 @@ const customRule = {
if (type === "link_open" && url.hash !== "") {
const fileContent = fs.readFileSync(url, { encoding: "utf8" })
const headings = getMarkdownHeadings(fileContent)
const anchorHTMLFragments =
getMarkdownAnchorHTMLFragments(fileContent)
/** @type {Map<string, number>} */
const fragments = new Map()
@@ -77,6 +80,8 @@ const customRule = {
return fragment
})
headingsHTMLFragments.push(...anchorHTMLFragments)
if (!headingsHTMLFragments.includes(url.hash)) {
onError({
lineNumber,