mirror of
https://github.com/theoludwig/markdownlint-rule-relative-links.git
synced 2026-06-09 23:25:33 +02:00
feat!: stricter validation of image links (check if the file is an image)
BREAKING CHANGE: links like  will now report an error
This commit is contained in:
+12
-2
@@ -1,5 +1,6 @@
|
||||
import { pathToFileURL } from "node:url"
|
||||
import { fileURLToPath, pathToFileURL } from "node:url"
|
||||
import fs from "node:fs"
|
||||
import mime from "mime"
|
||||
|
||||
import { filterTokens } from "./markdownlint-rule-helpers/helpers.js"
|
||||
import {
|
||||
@@ -69,7 +70,7 @@ const relativeLinksRule = {
|
||||
url = new URL(hrefSrc, pathToFileURL(params.name))
|
||||
}
|
||||
|
||||
if (url.protocol !== "file:") {
|
||||
if (url.protocol !== "file:" && type !== "image") {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -83,6 +84,15 @@ const relativeLinksRule = {
|
||||
continue
|
||||
}
|
||||
|
||||
const mimeType = mime.getType(fileURLToPath(url))
|
||||
if (type === "image" && (mimeType == null || !mimeType.startsWith("image/"))) {
|
||||
onError({
|
||||
lineNumber,
|
||||
detail: `${detail} should be an image`,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
if (url.hash.length <= 0) {
|
||||
if (hrefSrc.includes("#")) {
|
||||
if (type === "image") {
|
||||
|
||||
Reference in New Issue
Block a user