forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
md026.js
43 lines (39 loc) · 1.28 KB
/
md026.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// @ts-check
"use strict";
const { addError, allPunctuationNoQuestion, escapeForRegExp, forEachHeading } =
require("../helpers");
const endOfLineHtmlEntityRe = /&#?[\da-zA-Z]+;$/;
module.exports = {
"names": [ "MD026", "no-trailing-punctuation" ],
"description": "Trailing punctuation in heading",
"tags": [ "headings", "headers" ],
"function": function MD026(params, onError) {
let punctuation = params.config.punctuation;
punctuation = String(
(punctuation === undefined) ? allPunctuationNoQuestion : punctuation
);
const trailingPunctuationRe =
new RegExp("\\s*[" + escapeForRegExp(punctuation) + "]+$");
forEachHeading(params, (heading) => {
const { line, lineNumber } = heading;
const trimmedLine = line.replace(/([^\s#])[\s#]+$/, "$1");
const match = trailingPunctuationRe.exec(trimmedLine);
if (match && !endOfLineHtmlEntityRe.test(trimmedLine)) {
const fullMatch = match[0];
const column = match.index + 1;
const length = fullMatch.length;
addError(
onError,
lineNumber,
`Punctuation: '${fullMatch}'`,
null,
[ column, length ],
{
"editColumn": column,
"deleteCount": length
}
);
}
});
}
};