mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Move each rule implementation into its own file (fixes #83).
This commit is contained in:
parent
49e36f817c
commit
9ba143555d
42 changed files with 1289 additions and 1028 deletions
36
lib/md039.js
Normal file
36
lib/md039.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// @ts-check
|
||||
|
||||
"use strict";
|
||||
|
||||
var shared = require("./shared");
|
||||
|
||||
var spaceInLinkRe = /\[(?:\s+(?:[^\]]*?)\s*|(?:[^\]]*?)\s+)](?=\(\S*\))/;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD039", "no-space-in-links" ],
|
||||
"description": "Spaces inside link text",
|
||||
"tags": [ "whitespace", "links" ],
|
||||
"function": function MD039(params, onError) {
|
||||
shared.filterTokens(params, "inline", function forToken(token) {
|
||||
var inLink = false;
|
||||
var linkText = "";
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === "link_open") {
|
||||
inLink = true;
|
||||
linkText = "";
|
||||
} else if (child.type === "link_close") {
|
||||
inLink = false;
|
||||
var left = shared.trimLeft(linkText).length !== linkText.length;
|
||||
var right = shared.trimRight(linkText).length !== linkText.length;
|
||||
if (left || right) {
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
"[" + linkText + "]", left, right,
|
||||
shared.rangeFromRegExp(token.line, spaceInLinkRe));
|
||||
}
|
||||
} else if (inLink) {
|
||||
linkText += child.content;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue