Created
May 19, 2020 10:06
-
-
Save mwoodbri/af1b5bfb2e76376e3a37c1e3f118930f to your computer and use it in GitHub Desktop.
Custom rule for markdownlint that disallows non-https links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
names: ["http-link-warning"], | |
description: "Rule that reports an error for non-https links", | |
tags: ["links"], | |
function(params, onError) { | |
params.tokens | |
.filter((token) => token.type === "inline") | |
.flatMap((token) => token.children) | |
.filter( | |
(token) => | |
token.type === "link_open" && | |
token.attrs.some( | |
(attr) => attr[0] === "href" && attr[1].startsWith("http:") | |
) | |
) | |
.forEach((token) => | |
onError({ | |
lineNumber: token.lineNumber, | |
detail: token.attrs.find( | |
(attr) => attr[0] === "href" && attr[1].startsWith("http:") | |
)[1], | |
}) | |
); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment