Skip to content

Commit

Permalink
Capture and verify (for regression purposes) the markdown-it token st…
Browse files Browse the repository at this point in the history
…ream for markdownItPlugin tests.
  • Loading branch information
DavidAnson committed Jan 16, 2025
1 parent 6a515c0 commit 5d000b1
Show file tree
Hide file tree
Showing 13 changed files with 1,567 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/markdownItPlugins/custom-rule-assert-markdown-it-tokens.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check

import { deepEqual } from "node:assert";
import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { __dirname } from "../esm-helpers.mjs";

/** @type {import("markdownlint").Rule} */
export default {
"names": [ "assert-markdown-it-tokens" ],
"description": "Rule that asserts markdown-it tokens",
"tags": [ "test" ],
"parser": "markdownit",
"function": (params) => {
const file = resolve(
__dirname(import.meta),
params.config.file
);
const actual = params.parsers.markdownit.tokens;
const expected = JSON.parse(
readFileSync(
file,
"utf8"
)
);
writeFileSync(
file,
JSON.stringify(
actual,
null,
2
),
"utf8"
);
deepEqual(actual, expected);
}
};
204 changes: 204 additions & 0 deletions test/markdownItPlugins/file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
[
{
"type": "heading_open",
"tag": "h1",
"attrs": null,
"map": [
0,
1
],
"nesting": 1,
"level": 0,
"children": null,
"content": "",
"markup": "#",
"info": "",
"meta": null,
"block": true,
"hidden": false,
"line": "# Heading",
"lineNumber": 1
},
{
"type": "inline",
"tag": "",
"attrs": null,
"map": [
0,
1
],
"nesting": 0,
"level": 1,
"children": [
{
"type": "text",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 0,
"children": null,
"content": "Heading",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false,
"lineNumber": 1,
"line": "# Heading"
}
],
"content": "Heading",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false,
"line": "# Heading",
"lineNumber": 1
},
{
"type": "heading_close",
"tag": "h1",
"attrs": null,
"map": null,
"nesting": -1,
"level": 0,
"children": null,
"content": "",
"markup": "#",
"info": "",
"meta": null,
"block": true,
"hidden": false
},
{
"type": "paragraph_open",
"tag": "p",
"attrs": null,
"map": [
2,
3
],
"nesting": 1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false,
"line": "Text [ link ](https://example.com)",
"lineNumber": 3
},
{
"type": "inline",
"tag": "",
"attrs": null,
"map": [
2,
3
],
"nesting": 0,
"level": 1,
"children": [
{
"type": "text",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 0,
"children": null,
"content": "Text",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false,
"lineNumber": 3,
"line": "Text [ link ](https://example.com)"
},
{
"type": "link_open",
"tag": "a",
"attrs": [
[
"href",
"https://example.com"
]
],
"map": null,
"nesting": 1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false,
"lineNumber": 3,
"line": "Text [ link ](https://example.com)"
},
{
"type": "text",
"tag": "",
"attrs": null,
"map": null,
"nesting": 0,
"level": 1,
"children": null,
"content": "link",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false,
"lineNumber": 3,
"line": "Text [ link ](https://example.com)"
},
{
"type": "link_close",
"tag": "a",
"attrs": null,
"map": null,
"nesting": -1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": false,
"hidden": false,
"lineNumber": 3,
"line": "Text [ link ](https://example.com)"
}
],
"content": "Text [ link ](https://example.com)",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false,
"line": "Text [ link ](https://example.com)",
"lineNumber": 3
},
{
"type": "paragraph_close",
"tag": "p",
"attrs": null,
"map": null,
"nesting": -1,
"level": 0,
"children": null,
"content": "",
"markup": "",
"info": "",
"meta": null,
"block": true,
"hidden": false
}
]
8 changes: 8 additions & 0 deletions test/markdownItPlugins/file/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"config": {
"assert-markdown-it-tokens": {
"file": "file.json"
}
},
"customRules": [
"../custom-rule-assert-markdown-it-tokens.mjs"
],
"markdownItPlugins": [
[ "./custom-markdown-it-plugin.cjs" ]
]
Expand Down
Loading

0 comments on commit 5d000b1

Please sign in to comment.