mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2024-11-04 18:21:31 +01:00
feat: stricter validation of heading fragments by being Case sensitive
Fixes #8 BREAKING CHANGE: Heading fragments is now Case sensitive. For example "#ExistIng-Heading" is invalid as it should be "#existing-heading".
This commit is contained in:
parent
450cdb84f0
commit
85f465306f
@ -126,7 +126,7 @@ const customRule = {
|
||||
|
||||
fragmentsHTML.push(...idOrAnchorNameHTMLFragments)
|
||||
|
||||
if (!fragmentsHTML.includes(url.hash.toLowerCase())) {
|
||||
if (!fragmentsHTML.includes(url.hash)) {
|
||||
if (url.hash.startsWith("#L")) {
|
||||
const lineNumberFragmentString = getLineNumberStringFromFragment(
|
||||
url.hash,
|
||||
@ -157,6 +157,8 @@ const customRule = {
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
onError({
|
||||
|
@ -28,7 +28,7 @@ const convertHeadingToHTMLFragment = (inlineText) => {
|
||||
"",
|
||||
)
|
||||
.replace(/ /gu, "-"),
|
||||
).toLowerCase()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
# Valid
|
||||
|
||||
[Link fragment](./awesome.md#L7)
|
||||
[Link fragment](./awesome.md#l7)
|
||||
|
@ -47,6 +47,14 @@ test("ensure the rule validates correctly", async (t) => {
|
||||
'"./awesome.md#not-an-id-should-be-ignored" should have a valid fragment identifier',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "should be invalid with uppercase letters in fragment (case sensitive)",
|
||||
fixturePath:
|
||||
"test/fixtures/invalid/invalid-heading-case-sensitive/invalid-heading-case-sensitive.md",
|
||||
errors: [
|
||||
'"./awesome.md#ExistIng-Heading" should have a valid fragment identifier',
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "should be invalid with invalid heading with #L fragment",
|
||||
fixturePath:
|
||||
@ -148,7 +156,11 @@ test("ensure the rule validates correctly", async (t) => {
|
||||
)
|
||||
return result.errorDetail
|
||||
})
|
||||
assert.deepStrictEqual(errorsDetails, errors)
|
||||
assert.deepStrictEqual(
|
||||
errorsDetails,
|
||||
errors,
|
||||
`${fixturePath}: Expected errors`,
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
@ -165,11 +177,6 @@ test("ensure the rule validates correctly", async (t) => {
|
||||
fixturePath:
|
||||
"test/fixtures/valid/existing-element-id-fragment/existing-element-id-fragment.md",
|
||||
},
|
||||
{
|
||||
name: "should be valid with an existing heading fragment (case insensitive)",
|
||||
fixturePath:
|
||||
"test/fixtures/valid/existing-heading-case-insensitive/existing-heading-case-insensitive.md",
|
||||
},
|
||||
{
|
||||
name: "should be valid with an existing heading fragment",
|
||||
fixturePath:
|
||||
@ -232,7 +239,7 @@ test("ensure the rule validates correctly", async (t) => {
|
||||
assert.equal(
|
||||
errorsDetails.length,
|
||||
0,
|
||||
`Expected no errors, got ${errorsDetails.join(", ")}`,
|
||||
`${fixturePath}: Expected no errors, got ${errorsDetails.join(", ")}`,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user