mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2025-05-27 11:37:24 +02:00
feat: html anchor support
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
# Valid
|
||||
|
||||
<a name="existing-heading-anchor" ></a>
|
||||
|
||||
## Existing Heading
|
||||
|
@ -1,3 +1,5 @@
|
||||
# Invalid
|
||||
|
||||
[Link fragment](./awesome.md#non-existing-heading)
|
||||
|
||||
[Link fragment](./awesome.md#non-existing-heading-anchor)
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Valid
|
||||
|
||||
<a name="existing-heading-anchor" ></a>
|
||||
|
||||
## Existing Heading
|
||||
|
||||
### Repeated Heading
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
[Link fragment](./awesome.md#existing-heading)
|
||||
|
||||
[Link fragment](./awesome.md#existing-heading-anchor)
|
||||
|
||||
[Link fragment Repeated 0](./awesome.md#repeated-heading)
|
||||
|
||||
[Link fragment Repeated 1](./awesome.md#repeated-heading-1)
|
||||
|
@ -65,16 +65,22 @@ test("ensure the rule validates correctly", async (t) => {
|
||||
const lintResults = await validateMarkdownLint(
|
||||
"test/fixtures/invalid/non-existing-heading-fragment/non-existing-heading-fragment.md",
|
||||
)
|
||||
assert.equal(lintResults?.length, 1)
|
||||
assert.deepEqual(lintResults?.[0]?.ruleNames, relativeLinksRule.names)
|
||||
assert.equal(
|
||||
lintResults?.[0]?.ruleDescription,
|
||||
relativeLinksRule.description,
|
||||
)
|
||||
assert.equal(lintResults?.length, 2)
|
||||
for (let i = 0; i < 2; i++) {
|
||||
assert.deepEqual(lintResults?.[i]?.ruleNames, relativeLinksRule.names)
|
||||
assert.equal(
|
||||
lintResults?.[i]?.ruleDescription,
|
||||
relativeLinksRule.description,
|
||||
)
|
||||
}
|
||||
assert.equal(
|
||||
lintResults?.[0]?.errorDetail,
|
||||
'"./awesome.md#non-existing-heading" should have a valid fragment identifier',
|
||||
)
|
||||
assert.equal(
|
||||
lintResults?.[1]?.errorDetail,
|
||||
'"./awesome.md#non-existing-heading-anchor" should have a valid fragment identifier',
|
||||
)
|
||||
})
|
||||
|
||||
await t.test("with a non-existing file", async () => {
|
||||
|
@ -4,6 +4,7 @@ const assert = require("node:assert/strict")
|
||||
const {
|
||||
convertHeadingToHTMLFragment,
|
||||
getMarkdownHeadings,
|
||||
getMarkdownAnchorHTMLFragments,
|
||||
} = require("../src/utils.js")
|
||||
|
||||
test("utils", async (t) => {
|
||||
@ -34,4 +35,17 @@ test("utils", async (t) => {
|
||||
["Hello", "World", "Hello, world!"],
|
||||
)
|
||||
})
|
||||
|
||||
await t.test("getMarkdownAnchorHTMLFragments", async () => {
|
||||
assert.deepStrictEqual(
|
||||
getMarkdownAnchorHTMLFragments('<a name="anchorName" id="anchorId"></a>'),
|
||||
["#anchorId"],
|
||||
)
|
||||
assert.deepStrictEqual(
|
||||
getMarkdownAnchorHTMLFragments('<a name="anchorName"></a>'),
|
||||
["#anchorName"],
|
||||
)
|
||||
assert.deepStrictEqual(getMarkdownAnchorHTMLFragments("<a></a>"), [])
|
||||
assert.deepStrictEqual(getMarkdownAnchorHTMLFragments("<a>"), [])
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user