Skip to content

Commit 78a65d5

Browse files
committed
Stub-out micromark extension support for inline directives due to frequent over-matching of normal content.
1 parent 4491ee1 commit 78a65d5

5 files changed

Lines changed: 28 additions & 8 deletions

demo/default.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@
5555
if (renderer === "markdown-it") {
5656
return markdownit({ "html": true }).render(markdown);
5757
} else if (renderer === "micromark") {
58+
// See lib/micromark-parse.mjs
59+
const micromarkDirectiveNoInline = {
60+
...micromark.directive()
61+
};
62+
delete micromarkDirectiveNoInline.text;
5863
const parseOptions = {
5964
"extensions": [
60-
micromark.directive(),
65+
micromarkDirectiveNoInline,
6166
micromark.gfmAutolinkLiteral(),
6267
micromark.gfmFootnote(),
6368
micromark.gfmTable(),

lib/micromark-parse.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,28 @@ import { isHtmlFlowComment } from "../helpers/micromark-helpers.cjs";
1313
import { flatTokensSymbol, htmlFlowSymbol, newLineRe } from "../helpers/shared.cjs";
1414

1515
/** @typedef {import("micromark-util-types").Event} Event */
16+
/** @typedef {import("micromark-util-types").Extension} Extension */
1617
/** @typedef {import("micromark-util-types").ParseOptions} MicromarkParseOptions */
1718
/** @typedef {import("micromark-util-types").State} State */
1819
/** @typedef {import("micromark-util-types").Token} Token */
1920
/** @typedef {import("micromark-util-types").Tokenizer} Tokenizer */
2021
/** @typedef {import("markdownlint").MicromarkToken} MicromarkToken */
2122
/** @typedef {import("./micromark-types.d.mts")} */
2223

24+
/**
25+
* Gets a modified micromark-extension-directive without support for inline directives.
26+
*
27+
* @see {@link https://github.com/DavidAnson/markdownlint/issues/2080}
28+
* @returns {Extension} Modified implementation.
29+
*/
30+
function directiveNoInline() {
31+
const extension = {
32+
...directive()
33+
};
34+
delete extension.text;
35+
return extension;
36+
}
37+
2338
/**
2439
* Gets the Markdown text for a Micromark token.
2540
*
@@ -51,7 +66,7 @@ export function getEvents(
5166
) {
5267
// Customize extensions list to add useful extensions
5368
const extensions = [
54-
directive(),
69+
directiveNoInline(),
5570
gfmAutolinkLiteral(),
5671
gfmFootnote(),
5772
gfmTable(),
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Link Fragments Inline Directive
22

3-
## Time 12\:34
3+
## Time 12:34
44

55
[Time](#time-1234)
66

7-
## Ratio 16\:9
7+
## Ratio 16:9
88

99
[Ratio](#ratio-169)
1010

11-
## Stock NYSE\:MSFT
11+
## Stock NYSE:MSFT
1212

1313
[Stock](#stock-nysemsft)
1414

15-
## Spreadsheet A1\:B2
15+
## Spreadsheet A1:B2
1616

1717
[Spreadsheet](#spreadsheet-a1b2)

test/markdownlint-test-micromark.mjs.snapshot

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

test/markdownlint-test-scenarios.mjs.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21519,7 +21519,7 @@ exports[`markdownlint-test-scenarios.mjs > link-fragments-ignored-pattern-presen
2151921519
exports[`markdownlint-test-scenarios.mjs > link-fragments-inline-directive.md 1`] = `
2152021520
{
2152121521
"errors": [],
21522-
"fixed": "# Link Fragments Inline Directive\\n\\n## Time 12\\\\:34\\n\\n[Time](#time-1234)\\n\\n## Ratio 16\\\\:9\\n\\n[Ratio](#ratio-169)\\n\\n## Stock NYSE\\\\:MSFT\\n\\n[Stock](#stock-nysemsft)\\n\\n## Spreadsheet A1\\\\:B2\\n\\n[Spreadsheet](#spreadsheet-a1b2)\\n"
21522+
"fixed": "# Link Fragments Inline Directive\\n\\n## Time 12:34\\n\\n[Time](#time-1234)\\n\\n## Ratio 16:9\\n\\n[Ratio](#ratio-169)\\n\\n## Stock NYSE:MSFT\\n\\n[Stock](#stock-nysemsft)\\n\\n## Spreadsheet A1:B2\\n\\n[Spreadsheet](#spreadsheet-a1b2)\\n"
2152321523
}
2152421524
`;
2152521525

0 commit comments

Comments
 (0)