mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Reimplement MD037/no-space-in-emphasis using micromark tokens, report start/end separately for smaller edit spans, remove markdown-it-texmath (fixes #533, fixes #597).
This commit is contained in:
parent
e86fb7699d
commit
73b9704159
20 changed files with 1784 additions and 2502 deletions
|
|
@ -895,333 +895,6 @@ test("applyFixes", (t) => {
|
|||
}
|
||||
});
|
||||
|
||||
test("forEachLink", (t) => {
|
||||
t.plan(291);
|
||||
const testCases = [
|
||||
[
|
||||
"",
|
||||
[]
|
||||
],
|
||||
[
|
||||
"Text",
|
||||
[]
|
||||
],
|
||||
[
|
||||
"Text [text] (text) text",
|
||||
[ [ 5, "[text]", "[text]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [text] text (text) text",
|
||||
[ [ 5, "[text]", "[text]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [text] [text] text",
|
||||
[
|
||||
[ 5, "[text]", "[text]", undefined ],
|
||||
[ 12, "[text]", "[text]", undefined ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [text] text [text] text",
|
||||
[
|
||||
[ 5, "[text]", "[text]", undefined ],
|
||||
[ 17, "[text]", "[text]", undefined ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](destination) text",
|
||||
[ [ 5, "[link](destination)", "[link]", "(destination)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link0](destination0) text [link1](destination1) text",
|
||||
[
|
||||
[ 5, "[link0](destination0)", "[link0]", "(destination0)" ],
|
||||
[ 32, "[link1](destination1)", "[link1]", "(destination1)" ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link0] text [link1](destination1) text [link2] text",
|
||||
[
|
||||
[ 5, "[link0]", "[link0]", undefined ],
|
||||
[ 18, "[link1](destination1)", "[link1]", "(destination1)" ],
|
||||
[ 45, "[link2]", "[link2]", undefined ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link0](destination0) text [link1] text [link2](destination2) text",
|
||||
[
|
||||
[ 5, "[link0](destination0)", "[link0]", "(destination0)" ],
|
||||
[ 32, "[link1]", "[link1]", undefined ],
|
||||
[ 45, "[link2](destination2)", "[link2]", "(destination2)" ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link0][destination0] text [link1] text [link2](destination2) text",
|
||||
[
|
||||
[ 5, "[link0][destination0]", "[link0]", "[destination0]" ],
|
||||
[ 32, "[link1]", "[link1]", undefined ],
|
||||
[ 45, "[link2](destination2)", "[link2]", "(destination2)" ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link0](destination0) text [link1] text [link2][destination2] text",
|
||||
[
|
||||
[ 5, "[link0](destination0)", "[link0]", "(destination0)" ],
|
||||
[ 32, "[link1]", "[link1]", undefined ],
|
||||
[ 45, "[link2][destination2]", "[link2]", "[destination2]" ]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](destination \"title\") text",
|
||||
[
|
||||
[
|
||||
5,
|
||||
"[link](destination \"title\")",
|
||||
"[link]",
|
||||
"(destination \"title\")"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](<destination> \"title\") text",
|
||||
[
|
||||
[
|
||||
5,
|
||||
"[link](<destination> \"title\")",
|
||||
"[link]",
|
||||
"(<destination> \"title\")"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](destination \"ti\\\"tle\") text",
|
||||
[
|
||||
[
|
||||
5,
|
||||
"[link](destination \"ti\\\"tle\")",
|
||||
"[link]",
|
||||
"(destination \"ti\\\"tle\")"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](destination 'title') text",
|
||||
[
|
||||
[
|
||||
5,
|
||||
"[link](destination 'title')",
|
||||
"[link]",
|
||||
"(destination 'title')"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](destination (title)) text",
|
||||
[
|
||||
[
|
||||
5,
|
||||
"[link](destination (title))",
|
||||
"[link]",
|
||||
"(destination (title))"
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
"Text [link](\"title\") text",
|
||||
[ [ 5, "[link](\"title\")", "[link]", "(\"title\")" ] ]
|
||||
],
|
||||
[
|
||||
"[]()",
|
||||
[ [ 0, "[]()", "[]", "()" ] ]
|
||||
],
|
||||
[
|
||||
"[l](d)",
|
||||
[ [ 0, "[l](d)", "[l]", "(d)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [li[nk](dest) text",
|
||||
[ [ 8, "[nk](dest)", "[nk]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [li\\[nk](dest) text",
|
||||
[ [ 5, "[li\\[nk](dest)", "[li\\[nk]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [li]nk](dest) text",
|
||||
[ [ 5, "[li]", "[li]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [li\\]nk](dest) text",
|
||||
[ [ 5, "[li\\]nk](dest)", "[li\\]nk]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [l[in]k](dest) text",
|
||||
[ [ 5, "[l[in]k](dest)", "[l[in]k]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [li(nk](dest) text",
|
||||
[ [ 5, "[li(nk](dest)", "[li(nk]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [li)nk](dest) text",
|
||||
[ [ 5, "[li)nk](dest)", "[li)nk]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [l(in)k](dest) text",
|
||||
[ [ 5, "[l(in)k](dest)", "[l(in)k]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](de(st) text",
|
||||
[ [ 5, "[link]", "[link]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](de\\(st) text",
|
||||
[ [ 5, "[link](de\\(st)", "[link]", "(de\\(st)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](de)st) text",
|
||||
[ [ 5, "[link](de)", "[link]", "(de)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](de\\)st) text",
|
||||
[ [ 5, "[link](de\\)st)", "[link]", "(de\\)st)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](d(es)t) text",
|
||||
[ [ 5, "[link](d(es)t)", "[link]", "(d(es)t)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link]() text",
|
||||
[ [ 5, "[link]()", "[link]", "()" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](#) text",
|
||||
[ [ 5, "[link](#)", "[link]", "(#)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<de) text",
|
||||
[ [ 5, "[link]", "[link]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<de)st> text",
|
||||
[ [ 5, "[link]", "[link]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<>) text",
|
||||
[ [ 5, "[link](<>)", "[link]", "(<>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<dest>) text",
|
||||
[ [ 5, "[link](<dest>)", "[link]", "(<dest>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<de st>) text",
|
||||
[ [ 5, "[link](<de st>)", "[link]", "(<de st>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<de)st>) text",
|
||||
[ [ 5, "[link](<de)st>)", "[link]", "(<de)st>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [<link](dest) text",
|
||||
[ [ 5, "[<link](dest)", "[<link]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [<link>](dest) text",
|
||||
[ [ 5, "[<link>](dest)", "[<link>]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [<link>](<dest) text",
|
||||
[ [ 5, "[<link>]", "[<link>]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [<link>](<dest>) text",
|
||||
[ [ 5, "[<link>](<dest>)", "[<link>]", "(<dest>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [[[[l[i]n[k]](dest) text",
|
||||
[ [ 8, "[l[i]n[k]](dest)", "[l[i]n[k]]", "(dest)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](d(e(st))) text",
|
||||
[ [ 5, "[link](d(e(st)))", "[link]", "(d(e(st)))" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](d(e(st)) text",
|
||||
[ [ 5, "[link]", "[link]", undefined ] ]
|
||||
],
|
||||
[
|
||||
"Text [link](<d(e(st)>) text",
|
||||
[ [ 5, "[link](<d(e(st)>)", "[link]", "(<d(e(st)>)" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link][reference] text",
|
||||
[ [ 5, "[link][reference]", "[link]", "[reference]" ] ]
|
||||
],
|
||||
[
|
||||
"Text [link][refer]ence] text",
|
||||
[ [ 5, "[link][refer]", "[link]", "[refer]" ] ]
|
||||
]
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
const [ markdown, matches ] = testCase;
|
||||
helpers.forEachLink(String(markdown), (idx, lnk, txt, des) => {
|
||||
// @ts-ignore
|
||||
const match = matches.shift();
|
||||
const [ index, link, text, destination ] = match;
|
||||
t.is(idx, index, String(markdown));
|
||||
t.is(lnk, link, String(markdown));
|
||||
t.is(txt, text, String(markdown));
|
||||
t.is(des, destination, String(markdown));
|
||||
});
|
||||
t.is(matches.length, 0, "Missing match");
|
||||
}
|
||||
});
|
||||
|
||||
test("htmlElementRanges", (t) => {
|
||||
t.plan(1);
|
||||
const params = {
|
||||
"lines": [
|
||||
"# Heading",
|
||||
"",
|
||||
"Text text text",
|
||||
"text <a id='id'/> text",
|
||||
"text text text",
|
||||
"",
|
||||
"<p>",
|
||||
"Text <em>text</em> text",
|
||||
"</p>",
|
||||
"",
|
||||
"```",
|
||||
"<br/>",
|
||||
"```",
|
||||
"",
|
||||
"Text `<br/>` text",
|
||||
"text <br/> text"
|
||||
],
|
||||
"parsers": {
|
||||
"markdownit": {
|
||||
"tokens": [
|
||||
{
|
||||
"type": "code_block",
|
||||
"map": [ 10, 12 ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
const expected = [
|
||||
[ 3, 5, 12 ],
|
||||
[ 6, 0, 3 ],
|
||||
[ 7, 5, 4 ],
|
||||
[ 14, 6, 5 ],
|
||||
[ 15, 5, 5 ]
|
||||
];
|
||||
const lineMetadata = helpers.getLineMetadata(params);
|
||||
const actual = helpers.htmlElementRanges(params, lineMetadata);
|
||||
t.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
test("expandTildePath", (t) => {
|
||||
t.plan(17);
|
||||
const homedir = os.homedir();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue