Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/rules/no-missing-link-fragments.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Examples of **correct** code for this rule:
[Link to top of page](#top)

[Link](#L2)

# <span class="icon-star"></span> Starred Projects

[Link to starred projects](#-starred-projects)
```

## Options
Expand Down
3 changes: 3 additions & 0 deletions src/rules/no-missing-link-fragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ function isGitHubLineReference(fragment) {
* @returns {string} The extracted text
*/
function extractText(node) {
if (node.type === "html") {
return "";
}
if ("value" in node) {
return /** @type {string} */ (node.value);
}
Expand Down
63 changes: 63 additions & 0 deletions tests/rules/no-missing-link-fragments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,37 @@ ruleTester.run("no-missing-link-fragments", rule, {
# foo_
[Link](#foo_)
`,
dedent`
# <picture></picture> Heading Name
[Link](#-heading-name)
`,
dedent`
# Heading Name <picture></picture>
[Link](#heading-name-)
`,
dedent`
# Heading <picture></picture> Name
[Link](#heading--name)
`,
dedent`
# <span>Text</span> Heading Name
[Link](#text-heading-name)
`,
dedent`
# ![alt text](img.png) Heading Name
[Link](#-heading-name)
`,
dedent`
# Heading Name ![alt text](img.png)
[Link](#heading-name-)
`,
{
code: dedent`
# <picture></picture> Heading Name
[Link](#-HEADING-NAME)
`,
options: [{ ignoreCase: true }],
},
],

invalid: [
Expand Down Expand Up @@ -480,5 +511,37 @@ ruleTester.run("no-missing-link-fragments", rule, {
},
],
},
{
code: dedent`
# <picture></picture> Heading Name
[Link](#heading-name)
`,
errors: [
{
messageId: "invalidFragment",
data: { fragment: "heading-name" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
{
code: dedent`
# ![alt text](img.png) Heading Name
[Link](#heading-name)
`,
errors: [
{
messageId: "invalidFragment",
data: { fragment: "heading-name" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
],
});