Skip to content

Commit

Permalink
fix: should only check valid fragments in markdown (.md) files
Browse files Browse the repository at this point in the history
  • Loading branch information
theoludwig committed Jan 30, 2024
1 parent 5c39afb commit e20ee54
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ const customRule = {
continue
}

if (!url.pathname.endsWith(".md")) {
continue
}

const fileContent = fs.readFileSync(url, { encoding: "utf8" })
const headings = getMarkdownHeadings(fileContent)
const idOrAnchorNameHTMLFragments =
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Awesome</title>
</head>
<body></body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Valid

[Link fragment HTML](./awesome.html#existing-heading)

[Link fragment TXT](./abc.txt#existing-heading)

[Link fragment Image](../../image.png#existing-heading)
5 changes: 5 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ test("ensure the rule validates correctly", async (t) => {
fixturePath:
"test/fixtures/valid/existing-heading-fragment/existing-heading-fragment.md",
},
{
name: "should only parse markdown files for fragments checking",
fixturePath:
"test/fixtures/valid/only-parse-markdown-files-for-fragments/only-parse-markdown-files-for-fragments.md",
},
{
name: "with an existing file",
fixturePath: "test/fixtures/valid/existing-file.md",
Expand Down

0 comments on commit e20ee54

Please sign in to comment.