forked from DavidAnson/markdownlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd034.js
More file actions
75 lines (72 loc) · 2.2 KB
/
md034.js
File metadata and controls
75 lines (72 loc) · 2.2 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// @ts-check
"use strict";
const { addErrorContext } = require("../helpers");
const { filterByPredicate, getHtmlTagInfo, parse } =
require("../helpers/micromark.cjs");
module.exports = {
"names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used",
"tags": [ "links", "url" ],
"function": function MD034(params, onError) {
const literalAutolinks = (tokens) => (
filterByPredicate(
tokens,
(token) => token.type === "literalAutolink",
(token) => {
const { children } = token;
const result = [];
for (let i = 0; i < children.length; i++) {
const openToken = children[i];
const openTagInfo = getHtmlTagInfo(openToken);
if (openTagInfo && !openTagInfo.close) {
let count = 1;
for (let j = i + 1; j < children.length; j++) {
const closeToken = children[j];
const closeTagInfo = getHtmlTagInfo(closeToken);
if (closeTagInfo && (openTagInfo.name === closeTagInfo.name)) {
if (closeTagInfo.close) {
count--;
if (count === 0) {
i = j;
break;
}
} else {
count++;
}
}
}
} else {
result.push(openToken);
}
}
return result;
}
)
);
if (literalAutolinks(params.parsers.micromark.tokens).length > 0) {
// Re-parse with correct link/image reference definition handling
const document = params.lines.join("\n");
const tokens = parse(document, undefined, false);
for (const token of literalAutolinks(tokens)) {
const range = [
token.startColumn,
token.endColumn - token.startColumn
];
const fixInfo = {
"editColumn": range[0],
"deleteCount": range[1],
"insertText": `<${token.text}>`
};
addErrorContext(
onError,
token.startLine,
token.text,
null,
null,
range,
fixInfo
);
}
}
}
};