@alexlit/lint-kit 107.0.0 → 107.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -11
- package/packages/config-commitlint/package.json +2 -2
- package/packages/config-eslint/package.json +4 -4
- package/packages/config-hooks/package.json +3 -3
- package/packages/config-markdownlint/node_modules/markdown-it/LICENSE +22 -0
- package/packages/config-markdownlint/node_modules/markdown-it/README.md +309 -0
- package/packages/config-markdownlint/node_modules/markdown-it/bin/markdown-it.js +117 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.js +8441 -0
- package/packages/config-markdownlint/node_modules/markdown-it/dist/markdown-it.min.js +3 -0
- package/packages/config-markdownlint/node_modules/markdown-it/index.js +4 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/entities.js +6 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_blocks.js +70 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/html_re.js +28 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/common/utils.js +317 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/index.js +7 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_destination.js +80 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_label.js +48 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/helpers/parse_link_title.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/index.js +582 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_block.js +131 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_core.js +61 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/parser_inline.js +192 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/commonmark.js +81 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/default.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/presets/zero.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/renderer.js +341 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/ruler.js +352 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/blockquote.js +226 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/code.js +34 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/fence.js +98 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/heading.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/hr.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/html_block.js +74 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/lheading.js +83 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/list.js +362 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/paragraph.js +51 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/reference.js +198 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/state_block.js +231 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_block/table.js +221 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/block.js +16 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/inline.js +13 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/linkify.js +142 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/normalize.js +21 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/replacements.js +105 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/smartquotes.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/state_core.js +20 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_core/text_join.js +45 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/autolink.js +76 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/backticks.js +63 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/balance_pairs.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/emphasis.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/entity.js +55 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/escape.js +71 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/fragments_join.js +41 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/html_inline.js +58 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/image.js +152 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/link.js +150 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/linkify.js +62 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/newline.js +46 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/state_inline.js +158 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/strikethrough.js +130 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/rules_inline/text.js +89 -0
- package/packages/config-markdownlint/node_modules/markdown-it/lib/token.js +201 -0
- package/packages/config-markdownlint/node_modules/markdown-it/package.json +87 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CHANGELOG.md +428 -0
- package/packages/config-markdownlint/node_modules/markdownlint/CONTRIBUTING.md +92 -0
- package/packages/config-markdownlint/node_modules/markdownlint/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/README.md +1026 -0
- package/packages/config-markdownlint/node_modules/markdownlint/demo/markdownlint-browser.js +6814 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/CustomRules.md +376 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Prettier.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/ReleaseProcess.md +20 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/Rules.md +2335 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md001.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md003.md +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md004.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md005.md +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md007.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md009.md +51 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md010.md +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md011.md +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md012.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md013.md +57 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md014.md +54 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md018.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md019.md +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md020.md +29 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md021.md +31 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md022.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md023.md +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md024.md +47 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md025.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md026.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md027.md +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md028.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md029.md +98 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md030.md +82 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md031.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md032.md +55 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md033.md +27 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md034.md +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md035.md +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md036.md +45 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md037.md +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md038.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md039.md +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md040.md +52 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md041.md +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md042.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md043.md +69 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md044.md +35 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md045.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md046.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md047.md +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md048.md +41 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md049.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md050.md +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md051.md +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md052.md +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md053.md +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/doc/md054.md +100 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/LICENSE +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/README.md +70 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/helpers.js +1025 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/micromark.cjs +426 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/package.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/helpers/shared.js +10 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/cache.js +21 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/configuration.d.ts +1152 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/constants.js +14 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.d.ts +406 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/markdownlint.js +1476 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md001.js +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md003.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md004.js +76 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md005.js +73 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md007.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md009.js +86 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md010.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md011.js +46 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md012.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md013.js +96 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md014.js +53 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md018.js +34 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md019.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md020.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md021.js +62 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md022.js +108 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md023.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md024.js +38 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md025.js +32 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md026.js +50 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md027.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md028.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md029.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md030.js +61 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md031.js +40 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md032.js +78 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md033.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md034.js +79 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md035.js +24 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md036.js +56 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md037.js +91 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md038.js +97 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md039.js +67 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md040.js +37 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md041.js +42 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md042.js +49 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md043.js +64 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md044.js +107 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md045.js +60 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md046.js +33 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md047.js +28 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md048.js +30 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md049-md050.js +89 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md051.js +172 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md052.js +39 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md053.js +59 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/md054.js +125 -0
- package/packages/config-markdownlint/node_modules/markdownlint/lib/rules.js +65 -0
- package/packages/config-markdownlint/node_modules/markdownlint/package.json +109 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.jsonc +297 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/.markdownlint.yaml +266 -0
- package/packages/config-markdownlint/node_modules/markdownlint/schema/markdownlint-config-schema.json +1762 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/all.json +5 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/cirosantilli.json +22 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/prettier.json +26 -0
- package/packages/config-markdownlint/node_modules/markdownlint/style/relaxed.json +12 -0
- package/packages/config-markdownlint/package.json +3 -3
- package/packages/config-prettier/README.md +16 -0
- package/packages/config-prettier/package.json +4 -4
- package/packages/config-stylelint/package.json +2 -2
- package/scripts/semver.sh +6 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, forEachLine, isBlankLine } = require("../helpers");
|
|
6
|
+
const { lineMetadata } = require("./cache");
|
|
7
|
+
|
|
8
|
+
const codeFencePrefixRe = /^(.*?)[`~]/;
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"names": [ "MD031", "blanks-around-fences" ],
|
|
12
|
+
"description": "Fenced code blocks should be surrounded by blank lines",
|
|
13
|
+
"tags": [ "code", "blank_lines" ],
|
|
14
|
+
"function": function MD031(params, onError) {
|
|
15
|
+
const listItems = params.config.list_items;
|
|
16
|
+
const includeListItems = (listItems === undefined) ? true : !!listItems;
|
|
17
|
+
const { lines } = params;
|
|
18
|
+
forEachLine(lineMetadata(), (line, i, inCode, onFence, inTable, inItem) => {
|
|
19
|
+
const onTopFence = (onFence > 0);
|
|
20
|
+
const onBottomFence = (onFence < 0);
|
|
21
|
+
if ((includeListItems || !inItem) &&
|
|
22
|
+
((onTopFence && !isBlankLine(lines[i - 1])) ||
|
|
23
|
+
(onBottomFence && !isBlankLine(lines[i + 1])))) {
|
|
24
|
+
const [ , prefix ] = line.match(codeFencePrefixRe) || [];
|
|
25
|
+
const fixInfo = (prefix === undefined) ? null : {
|
|
26
|
+
"lineNumber": i + (onTopFence ? 1 : 2),
|
|
27
|
+
"insertText": `${prefix.replace(/[^>]/g, " ").trim()}\n`
|
|
28
|
+
};
|
|
29
|
+
addErrorContext(
|
|
30
|
+
onError,
|
|
31
|
+
i + 1,
|
|
32
|
+
lines[i].trim(),
|
|
33
|
+
null,
|
|
34
|
+
null,
|
|
35
|
+
null,
|
|
36
|
+
fixInfo);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, blockquotePrefixRe, isBlankLine } =
|
|
6
|
+
require("../helpers");
|
|
7
|
+
const { filterByPredicate } = require("../helpers/micromark.cjs");
|
|
8
|
+
|
|
9
|
+
const nonContentTokens = new Set([
|
|
10
|
+
"blockQuoteMarker",
|
|
11
|
+
"blockQuotePrefix",
|
|
12
|
+
"blockQuotePrefixWhitespace",
|
|
13
|
+
"lineEnding",
|
|
14
|
+
"lineEndingBlank",
|
|
15
|
+
"linePrefix",
|
|
16
|
+
"listItemIndent"
|
|
17
|
+
]);
|
|
18
|
+
const isList = (token) => (
|
|
19
|
+
(token.type === "listOrdered") || (token.type === "listUnordered")
|
|
20
|
+
);
|
|
21
|
+
const addBlankLineError = (onError, lines, lineIndex, lineNumber) => {
|
|
22
|
+
const line = lines[lineIndex];
|
|
23
|
+
const quotePrefix = line.match(blockquotePrefixRe)[0].trimEnd();
|
|
24
|
+
addErrorContext(
|
|
25
|
+
onError,
|
|
26
|
+
lineIndex + 1,
|
|
27
|
+
line.trim(),
|
|
28
|
+
null,
|
|
29
|
+
null,
|
|
30
|
+
null,
|
|
31
|
+
{
|
|
32
|
+
lineNumber,
|
|
33
|
+
"insertText": `${quotePrefix}\n`
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
"names": [ "MD032", "blanks-around-lists" ],
|
|
40
|
+
"description": "Lists should be surrounded by blank lines",
|
|
41
|
+
"tags": [ "bullet", "ul", "ol", "blank_lines" ],
|
|
42
|
+
"function": function MD032(params, onError) {
|
|
43
|
+
const { lines, parsers } = params;
|
|
44
|
+
|
|
45
|
+
// For every top-level list...
|
|
46
|
+
const topLevelLists = filterByPredicate(
|
|
47
|
+
parsers.micromark.tokens,
|
|
48
|
+
isList,
|
|
49
|
+
(token) => (
|
|
50
|
+
(isList(token) || (token.type === "htmlFlow")) ? [] : token.children
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
for (const list of topLevelLists) {
|
|
54
|
+
|
|
55
|
+
// Look for a blank line above the list
|
|
56
|
+
const firstIndex = list.startLine - 1;
|
|
57
|
+
if (!isBlankLine(lines[firstIndex - 1])) {
|
|
58
|
+
addBlankLineError(onError, lines, firstIndex);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Find the "visual" end of the list
|
|
62
|
+
let endLine = list.endLine;
|
|
63
|
+
const flattenedChildren = filterByPredicate(list.children);
|
|
64
|
+
for (const child of flattenedChildren.reverse()) {
|
|
65
|
+
if (!nonContentTokens.has(child.type)) {
|
|
66
|
+
endLine = child.endLine;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Look for a blank line below the list
|
|
72
|
+
const lastIndex = endLine - 1;
|
|
73
|
+
if (!isBlankLine(lines[lastIndex + 1])) {
|
|
74
|
+
addBlankLineError(onError, lines, lastIndex, lastIndex + 2);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, nextLinesRe } = require("../helpers");
|
|
6
|
+
const { filterByTypes, getHtmlTagInfo } =
|
|
7
|
+
require("../helpers/micromark.cjs");
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
"names": [ "MD033", "no-inline-html" ],
|
|
11
|
+
"description": "Inline HTML",
|
|
12
|
+
"tags": [ "html" ],
|
|
13
|
+
"function": function MD033(params, onError) {
|
|
14
|
+
let allowedElements = params.config.allowed_elements;
|
|
15
|
+
allowedElements = Array.isArray(allowedElements) ? allowedElements : [];
|
|
16
|
+
allowedElements = allowedElements.map((element) => element.toLowerCase());
|
|
17
|
+
const { tokens } = params.parsers.micromark;
|
|
18
|
+
for (const token of filterByTypes(tokens, [ "htmlText" ])) {
|
|
19
|
+
const htmlTagInfo = getHtmlTagInfo(token);
|
|
20
|
+
if (
|
|
21
|
+
htmlTagInfo &&
|
|
22
|
+
!htmlTagInfo.close &&
|
|
23
|
+
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
|
|
24
|
+
) {
|
|
25
|
+
const range = [
|
|
26
|
+
token.startColumn,
|
|
27
|
+
token.text.replace(nextLinesRe, "").length
|
|
28
|
+
];
|
|
29
|
+
addError(
|
|
30
|
+
onError,
|
|
31
|
+
token.startLine,
|
|
32
|
+
"Element: " + htmlTagInfo.name,
|
|
33
|
+
undefined,
|
|
34
|
+
range
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { filterByPredicate, filterByTypes, getHtmlTagInfo, inHtmlFlow, parse } =
|
|
7
|
+
require("../helpers/micromark.cjs");
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
"names": [ "MD034", "no-bare-urls" ],
|
|
11
|
+
"description": "Bare URL used",
|
|
12
|
+
"tags": [ "links", "url" ],
|
|
13
|
+
"function": function MD034(params, onError) {
|
|
14
|
+
const literalAutolinks = (tokens) => (
|
|
15
|
+
filterByPredicate(
|
|
16
|
+
tokens,
|
|
17
|
+
(token) => (token.type === "literalAutolink") && !inHtmlFlow(token),
|
|
18
|
+
(token) => {
|
|
19
|
+
const { children } = token;
|
|
20
|
+
const result = [];
|
|
21
|
+
for (let i = 0; i < children.length; i++) {
|
|
22
|
+
const current = children[i];
|
|
23
|
+
const openTagInfo = getHtmlTagInfo(current);
|
|
24
|
+
if (openTagInfo && !openTagInfo.close) {
|
|
25
|
+
let count = 1;
|
|
26
|
+
for (let j = i + 1; j < children.length; j++) {
|
|
27
|
+
const candidate = children[j];
|
|
28
|
+
const closeTagInfo = getHtmlTagInfo(candidate);
|
|
29
|
+
if (closeTagInfo && (openTagInfo.name === closeTagInfo.name)) {
|
|
30
|
+
if (closeTagInfo.close) {
|
|
31
|
+
count--;
|
|
32
|
+
if (count === 0) {
|
|
33
|
+
i = j;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
count++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
result.push(current);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
const autoLinks = filterByTypes(
|
|
50
|
+
params.parsers.micromark.tokens,
|
|
51
|
+
[ "literalAutolink" ]
|
|
52
|
+
);
|
|
53
|
+
if (autoLinks.length > 0) {
|
|
54
|
+
// Re-parse with correct link/image reference definition handling
|
|
55
|
+
const document = params.lines.join("\n");
|
|
56
|
+
const tokens = parse(document, undefined, false);
|
|
57
|
+
for (const token of literalAutolinks(tokens)) {
|
|
58
|
+
const range = [
|
|
59
|
+
token.startColumn,
|
|
60
|
+
token.endColumn - token.startColumn
|
|
61
|
+
];
|
|
62
|
+
const fixInfo = {
|
|
63
|
+
"editColumn": range[0],
|
|
64
|
+
"deleteCount": range[1],
|
|
65
|
+
"insertText": `<${token.text}>`
|
|
66
|
+
};
|
|
67
|
+
addErrorContext(
|
|
68
|
+
onError,
|
|
69
|
+
token.startLine,
|
|
70
|
+
token.text,
|
|
71
|
+
null,
|
|
72
|
+
null,
|
|
73
|
+
range,
|
|
74
|
+
fixInfo
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorDetailIf } = require("../helpers");
|
|
6
|
+
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD035", "hr-style" ],
|
|
10
|
+
"description": "Horizontal rule style",
|
|
11
|
+
"tags": [ "hr" ],
|
|
12
|
+
"function": function MD035(params, onError) {
|
|
13
|
+
let style = String(params.config.style || "consistent").trim();
|
|
14
|
+
const thematicBreaks =
|
|
15
|
+
filterByTypes(params.parsers.micromark.tokens, [ "thematicBreak" ]);
|
|
16
|
+
for (const token of thematicBreaks) {
|
|
17
|
+
const { startLine, text } = token;
|
|
18
|
+
if (style === "consistent") {
|
|
19
|
+
style = text;
|
|
20
|
+
}
|
|
21
|
+
addErrorDetailIf(onError, startLine, style, text);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, allPunctuation } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD036", "no-emphasis-as-heading" ],
|
|
9
|
+
"description": "Emphasis used instead of a heading",
|
|
10
|
+
"tags": [ "headings", "emphasis" ],
|
|
11
|
+
"function": function MD036(params, onError) {
|
|
12
|
+
let punctuation = params.config.punctuation;
|
|
13
|
+
punctuation =
|
|
14
|
+
String((punctuation === undefined) ? allPunctuation : punctuation);
|
|
15
|
+
const re = new RegExp("[" + punctuation + "]$");
|
|
16
|
+
// eslint-disable-next-line jsdoc/require-jsdoc
|
|
17
|
+
function base(token) {
|
|
18
|
+
if (token.type === "paragraph_open") {
|
|
19
|
+
return function inParagraph(t) {
|
|
20
|
+
// Always paragraph_open/inline/paragraph_close,
|
|
21
|
+
const children = t.children.filter(function notEmptyText(child) {
|
|
22
|
+
return (child.type !== "text") || (child.content !== "");
|
|
23
|
+
});
|
|
24
|
+
if ((children.length === 3) &&
|
|
25
|
+
((children[0].type === "strong_open") ||
|
|
26
|
+
(children[0].type === "em_open")) &&
|
|
27
|
+
(children[1].type === "text") &&
|
|
28
|
+
!re.test(children[1].content)) {
|
|
29
|
+
addErrorContext(onError, t.lineNumber,
|
|
30
|
+
children[1].content);
|
|
31
|
+
}
|
|
32
|
+
return base;
|
|
33
|
+
};
|
|
34
|
+
} else if (token.type === "blockquote_open") {
|
|
35
|
+
return function inBlockquote(t) {
|
|
36
|
+
if (t.type !== "blockquote_close") {
|
|
37
|
+
return inBlockquote;
|
|
38
|
+
}
|
|
39
|
+
return base;
|
|
40
|
+
};
|
|
41
|
+
} else if (token.type === "list_item_open") {
|
|
42
|
+
return function inListItem(t) {
|
|
43
|
+
if (t.type !== "list_item_close") {
|
|
44
|
+
return inListItem;
|
|
45
|
+
}
|
|
46
|
+
return base;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return base;
|
|
50
|
+
}
|
|
51
|
+
let state = base;
|
|
52
|
+
for (const token of params.parsers.markdownit.tokens) {
|
|
53
|
+
state = state(token);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError } = require("../helpers");
|
|
6
|
+
const { filterByPredicate, inHtmlFlow } = require("../helpers/micromark.cjs");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
"names": [ "MD037", "no-space-in-emphasis" ],
|
|
10
|
+
"description": "Spaces inside emphasis markers",
|
|
11
|
+
"tags": [ "whitespace", "emphasis" ],
|
|
12
|
+
"function": function MD037(params, onError) {
|
|
13
|
+
|
|
14
|
+
// Initialize variables
|
|
15
|
+
const { lines, parsers } = params;
|
|
16
|
+
const emphasisTokensByMarker = new Map();
|
|
17
|
+
for (const marker of [ "_", "__", "___", "*", "**", "***" ]) {
|
|
18
|
+
emphasisTokensByMarker.set(marker, []);
|
|
19
|
+
}
|
|
20
|
+
const tokens = filterByPredicate(
|
|
21
|
+
parsers.micromark.tokens,
|
|
22
|
+
(token) => token.children.some((child) => child.type === "data")
|
|
23
|
+
);
|
|
24
|
+
for (const token of tokens) {
|
|
25
|
+
|
|
26
|
+
// Build lists of bare tokens for each emphasis marker type
|
|
27
|
+
for (const emphasisTokens of emphasisTokensByMarker.values()) {
|
|
28
|
+
emphasisTokens.length = 0;
|
|
29
|
+
}
|
|
30
|
+
for (const child of token.children) {
|
|
31
|
+
const { text, type } = child;
|
|
32
|
+
if ((type === "data") && (text.length <= 3)) {
|
|
33
|
+
const emphasisTokens = emphasisTokensByMarker.get(text);
|
|
34
|
+
if (emphasisTokens && !inHtmlFlow(child)) {
|
|
35
|
+
emphasisTokens.push(child);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Process bare tokens for each emphasis marker type
|
|
41
|
+
for (const entry of emphasisTokensByMarker.entries()) {
|
|
42
|
+
const [ marker, emphasisTokens ] = entry;
|
|
43
|
+
for (let i = 0; i + 1 < emphasisTokens.length; i += 2) {
|
|
44
|
+
|
|
45
|
+
// Process start token of start/end pair
|
|
46
|
+
const startToken = emphasisTokens[i];
|
|
47
|
+
const startLine = lines[startToken.startLine - 1];
|
|
48
|
+
const startSlice = startLine.slice(startToken.endColumn - 1);
|
|
49
|
+
const startMatch = startSlice.match(/^\s+\S/);
|
|
50
|
+
if (startMatch) {
|
|
51
|
+
const [ startSpaceCharacter ] = startMatch;
|
|
52
|
+
const startContext = `${marker}${startSpaceCharacter}`;
|
|
53
|
+
addError(
|
|
54
|
+
onError,
|
|
55
|
+
startToken.startLine,
|
|
56
|
+
undefined,
|
|
57
|
+
startContext,
|
|
58
|
+
[ startToken.startColumn, startContext.length ],
|
|
59
|
+
{
|
|
60
|
+
"editColumn": startToken.endColumn,
|
|
61
|
+
"deleteCount": startSpaceCharacter.length - 1
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Process end token of start/end pair
|
|
67
|
+
const endToken = emphasisTokens[i + 1];
|
|
68
|
+
const endLine = lines[endToken.startLine - 1];
|
|
69
|
+
const endSlice = endLine.slice(0, endToken.startColumn - 1);
|
|
70
|
+
const endMatch = endSlice.match(/\S\s+$/);
|
|
71
|
+
if (endMatch) {
|
|
72
|
+
const [ endSpaceCharacter ] = endMatch;
|
|
73
|
+
const endContext = `${endSpaceCharacter}${marker}`;
|
|
74
|
+
addError(
|
|
75
|
+
onError,
|
|
76
|
+
endToken.startLine,
|
|
77
|
+
undefined,
|
|
78
|
+
endContext,
|
|
79
|
+
[ endToken.endColumn - endContext.length, endContext.length ],
|
|
80
|
+
{
|
|
81
|
+
"editColumn":
|
|
82
|
+
endToken.startColumn - (endSpaceCharacter.length - 1),
|
|
83
|
+
"deleteCount": endSpaceCharacter.length - 1
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext } = require("../helpers");
|
|
6
|
+
const { filterByTypes, inHtmlFlow, tokenIfType } =
|
|
7
|
+
require("../helpers/micromark.cjs");
|
|
8
|
+
|
|
9
|
+
const leftSpaceRe = /^\s(?:[^`]|$)/;
|
|
10
|
+
const rightSpaceRe = /[^`]\s$/;
|
|
11
|
+
const trimCodeText = (text, start, end) => {
|
|
12
|
+
text = text.replace(/^\s+$/, "");
|
|
13
|
+
if (start) {
|
|
14
|
+
text = text.replace(/^\s+?(\s`|\S)/, "$1");
|
|
15
|
+
}
|
|
16
|
+
if (end) {
|
|
17
|
+
text = text.replace(/(`\s|\S)\s+$/, "$1");
|
|
18
|
+
}
|
|
19
|
+
return text;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
"names": [ "MD038", "no-space-in-code" ],
|
|
24
|
+
"description": "Spaces inside code span elements",
|
|
25
|
+
"tags": [ "whitespace", "code" ],
|
|
26
|
+
"function": function MD038(params, onError) {
|
|
27
|
+
const codeTexts =
|
|
28
|
+
filterByTypes(params.parsers.micromark.tokens, [ "codeText" ])
|
|
29
|
+
.filter((codeText) => !inHtmlFlow(codeText));
|
|
30
|
+
for (const codeText of codeTexts) {
|
|
31
|
+
const { children } = codeText;
|
|
32
|
+
const first = 0;
|
|
33
|
+
const last = children.length - 1;
|
|
34
|
+
const startSequence = tokenIfType(children[first], "codeTextSequence");
|
|
35
|
+
const endSequence = tokenIfType(children[last], "codeTextSequence");
|
|
36
|
+
const startData =
|
|
37
|
+
tokenIfType(children[first + 1], "codeTextData") ||
|
|
38
|
+
tokenIfType(children[first + 2], "codeTextData");
|
|
39
|
+
const endData =
|
|
40
|
+
tokenIfType(children[last - 1], "codeTextData") ||
|
|
41
|
+
tokenIfType(children[last - 2], "codeTextData");
|
|
42
|
+
if (startSequence && endSequence && startData && endData) {
|
|
43
|
+
const spaceLeft = leftSpaceRe.test(startData.text);
|
|
44
|
+
const spaceRight = !spaceLeft && rightSpaceRe.test(endData.text);
|
|
45
|
+
if (spaceLeft || spaceRight) {
|
|
46
|
+
let lineNumber = startSequence.startLine;
|
|
47
|
+
let range = null;
|
|
48
|
+
let fixInfo = null;
|
|
49
|
+
if (startSequence.startLine === endSequence.endLine) {
|
|
50
|
+
range = [
|
|
51
|
+
startSequence.startColumn,
|
|
52
|
+
endSequence.endColumn - startSequence.startColumn
|
|
53
|
+
];
|
|
54
|
+
fixInfo = {
|
|
55
|
+
"editColumn": startSequence.endColumn,
|
|
56
|
+
"deleteCount": endSequence.startColumn - startSequence.endColumn,
|
|
57
|
+
"insertText": trimCodeText(startData.text, true, true)
|
|
58
|
+
};
|
|
59
|
+
} else if (spaceLeft) {
|
|
60
|
+
range = [
|
|
61
|
+
startSequence.startColumn,
|
|
62
|
+
startData.endColumn - startSequence.startColumn
|
|
63
|
+
];
|
|
64
|
+
fixInfo = {
|
|
65
|
+
"editColumn": startSequence.endColumn,
|
|
66
|
+
"deleteCount": startData.endColumn - startData.startColumn,
|
|
67
|
+
"insertText": trimCodeText(startData.text, true, false)
|
|
68
|
+
};
|
|
69
|
+
} else {
|
|
70
|
+
lineNumber = endSequence.endLine;
|
|
71
|
+
range = [
|
|
72
|
+
endData.startColumn,
|
|
73
|
+
endSequence.endColumn - endData.startColumn
|
|
74
|
+
];
|
|
75
|
+
fixInfo = {
|
|
76
|
+
"editColumn": endData.startColumn,
|
|
77
|
+
"deleteCount": endData.endColumn - endData.startColumn,
|
|
78
|
+
"insertText": trimCodeText(endData.text, false, true)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const context = params
|
|
82
|
+
.lines[lineNumber - 1]
|
|
83
|
+
.substring(range[0] - 1, range[0] - 1 + range[1]);
|
|
84
|
+
addErrorContext(
|
|
85
|
+
onError,
|
|
86
|
+
lineNumber,
|
|
87
|
+
context,
|
|
88
|
+
spaceLeft,
|
|
89
|
+
spaceRight,
|
|
90
|
+
range,
|
|
91
|
+
fixInfo
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, filterTokens } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
const spaceInLinkRe =
|
|
8
|
+
/\[(?:\s[^\]]*|[^\]]*?\s)\](?=(\([^)]*\)|\[[^\]]*\]))/;
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"names": [ "MD039", "no-space-in-links" ],
|
|
12
|
+
"description": "Spaces inside link text",
|
|
13
|
+
"tags": [ "whitespace", "links" ],
|
|
14
|
+
"function": function MD039(params, onError) {
|
|
15
|
+
filterTokens(params, "inline", (token) => {
|
|
16
|
+
const { children } = token;
|
|
17
|
+
let { lineNumber } = token;
|
|
18
|
+
let inLink = false;
|
|
19
|
+
let linkText = "";
|
|
20
|
+
let lineIndex = 0;
|
|
21
|
+
for (const child of children) {
|
|
22
|
+
const { content, markup, type } = child;
|
|
23
|
+
if (type === "link_open") {
|
|
24
|
+
inLink = true;
|
|
25
|
+
linkText = "";
|
|
26
|
+
} else if (type === "link_close") {
|
|
27
|
+
inLink = false;
|
|
28
|
+
const left = linkText.trimStart().length !== linkText.length;
|
|
29
|
+
const right = linkText.trimEnd().length !== linkText.length;
|
|
30
|
+
if (left || right) {
|
|
31
|
+
const line = params.lines[lineNumber - 1];
|
|
32
|
+
let range = null;
|
|
33
|
+
let fixInfo = null;
|
|
34
|
+
const match = line.slice(lineIndex).match(spaceInLinkRe);
|
|
35
|
+
if (match) {
|
|
36
|
+
const column = match.index + lineIndex + 1;
|
|
37
|
+
const length = match[0].length;
|
|
38
|
+
range = [ column, length ];
|
|
39
|
+
fixInfo = {
|
|
40
|
+
"editColumn": column + 1,
|
|
41
|
+
"deleteCount": length - 2,
|
|
42
|
+
"insertText": linkText.trim()
|
|
43
|
+
};
|
|
44
|
+
lineIndex = column + length - 1;
|
|
45
|
+
}
|
|
46
|
+
addErrorContext(
|
|
47
|
+
onError,
|
|
48
|
+
lineNumber,
|
|
49
|
+
`[${linkText}]`,
|
|
50
|
+
left,
|
|
51
|
+
right,
|
|
52
|
+
range,
|
|
53
|
+
fixInfo
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
} else if ((type === "softbreak") || (type === "hardbreak")) {
|
|
57
|
+
lineNumber++;
|
|
58
|
+
lineIndex = 0;
|
|
59
|
+
} else if (inLink) {
|
|
60
|
+
linkText += type.endsWith("_inline") ?
|
|
61
|
+
`${markup}${content}${markup}` :
|
|
62
|
+
(content || markup);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addError, addErrorContext, filterTokens } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD040", "fenced-code-language" ],
|
|
9
|
+
"description": "Fenced code blocks should have a language specified",
|
|
10
|
+
"tags": [ "code", "language" ],
|
|
11
|
+
"function": function MD040(params, onError) {
|
|
12
|
+
let allowed = params.config.allowed_languages;
|
|
13
|
+
allowed = Array.isArray(allowed) ? allowed : [];
|
|
14
|
+
const languageOnly = !!params.config.language_only;
|
|
15
|
+
|
|
16
|
+
filterTokens(params, "fence", function forToken(token) {
|
|
17
|
+
const lang = token.info.trim().split(/\s+/u).shift();
|
|
18
|
+
if (lang === "") {
|
|
19
|
+
addErrorContext(onError, token.lineNumber, token.line);
|
|
20
|
+
} else if ((allowed.length > 0) && !allowed.includes(lang)) {
|
|
21
|
+
addError(
|
|
22
|
+
onError,
|
|
23
|
+
token.lineNumber,
|
|
24
|
+
`"${lang}" is not allowed`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (languageOnly && (token.info !== lang)) {
|
|
29
|
+
addError(
|
|
30
|
+
onError,
|
|
31
|
+
token.lineNumber,
|
|
32
|
+
`Info string contains more than language: "${token.info}"`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { addErrorContext, frontMatterHasTitle } = require("../helpers");
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
"names": [ "MD041", "first-line-heading", "first-line-h1" ],
|
|
9
|
+
"description": "First line in a file should be a top-level heading",
|
|
10
|
+
"tags": [ "headings" ],
|
|
11
|
+
"function": function MD041(params, onError) {
|
|
12
|
+
const level = Number(params.config.level || 1);
|
|
13
|
+
const tag = "h" + level;
|
|
14
|
+
const foundFrontMatterTitle =
|
|
15
|
+
frontMatterHasTitle(
|
|
16
|
+
params.frontMatterLines,
|
|
17
|
+
params.config.front_matter_title
|
|
18
|
+
);
|
|
19
|
+
if (!foundFrontMatterTitle) {
|
|
20
|
+
const htmlHeadingRe = new RegExp(`^<h${level}[ />]`, "i");
|
|
21
|
+
params.parsers.markdownit.tokens.every((token) => {
|
|
22
|
+
let isError = false;
|
|
23
|
+
if (token.type === "html_block") {
|
|
24
|
+
if (token.content.startsWith("<!--")) {
|
|
25
|
+
// Ignore leading HTML comments
|
|
26
|
+
return true;
|
|
27
|
+
} else if (!htmlHeadingRe.test(token.content)) {
|
|
28
|
+
// Something other than an HTML heading
|
|
29
|
+
isError = true;
|
|
30
|
+
}
|
|
31
|
+
} else if ((token.type !== "heading_open") || (token.tag !== tag)) {
|
|
32
|
+
// Something other than a Markdown heading
|
|
33
|
+
isError = true;
|
|
34
|
+
}
|
|
35
|
+
if (isError) {
|
|
36
|
+
addErrorContext(onError, token.lineNumber, token.line);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|