diff --git a/src/index.js b/src/index.js index dc074ef..7daa3df 100644 --- a/src/index.js +++ b/src/index.js @@ -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 = diff --git a/test/fixtures/valid/only-parse-markdown-files-for-fragments/abc.txt b/test/fixtures/valid/only-parse-markdown-files-for-fragments/abc.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/valid/only-parse-markdown-files-for-fragments/awesome.html b/test/fixtures/valid/only-parse-markdown-files-for-fragments/awesome.html new file mode 100644 index 0000000..a0bb4f4 --- /dev/null +++ b/test/fixtures/valid/only-parse-markdown-files-for-fragments/awesome.html @@ -0,0 +1,9 @@ + + + + + + Awesome + + + diff --git a/test/fixtures/valid/only-parse-markdown-files-for-fragments/only-parse-markdown-files-for-fragments.md b/test/fixtures/valid/only-parse-markdown-files-for-fragments/only-parse-markdown-files-for-fragments.md new file mode 100644 index 0000000..7496d74 --- /dev/null +++ b/test/fixtures/valid/only-parse-markdown-files-for-fragments/only-parse-markdown-files-for-fragments.md @@ -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) diff --git a/test/index.test.js b/test/index.test.js index 451d728..3aa493a 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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",