Skip to content

Commit 5d000b1

Browse files
committed
Capture and verify (for regression purposes) the markdown-it token stream for markdownItPlugin tests.
1 parent 6a515c0 commit 5d000b1

13 files changed

+1567
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @ts-check
2+
3+
import { deepEqual } from "node:assert";
4+
import { readFileSync, writeFileSync } from "node:fs";
5+
import { resolve } from "node:path";
6+
import { __dirname } from "../esm-helpers.mjs";
7+
8+
/** @type {import("markdownlint").Rule} */
9+
export default {
10+
"names": [ "assert-markdown-it-tokens" ],
11+
"description": "Rule that asserts markdown-it tokens",
12+
"tags": [ "test" ],
13+
"parser": "markdownit",
14+
"function": (params) => {
15+
const file = resolve(
16+
__dirname(import.meta),
17+
params.config.file
18+
);
19+
const actual = params.parsers.markdownit.tokens;
20+
const expected = JSON.parse(
21+
readFileSync(
22+
file,
23+
"utf8"
24+
)
25+
);
26+
writeFileSync(
27+
file,
28+
JSON.stringify(
29+
actual,
30+
null,
31+
2
32+
),
33+
"utf8"
34+
);
35+
deepEqual(actual, expected);
36+
}
37+
};

test/markdownItPlugins/file.json

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
[
2+
{
3+
"type": "heading_open",
4+
"tag": "h1",
5+
"attrs": null,
6+
"map": [
7+
0,
8+
1
9+
],
10+
"nesting": 1,
11+
"level": 0,
12+
"children": null,
13+
"content": "",
14+
"markup": "#",
15+
"info": "",
16+
"meta": null,
17+
"block": true,
18+
"hidden": false,
19+
"line": "# Heading",
20+
"lineNumber": 1
21+
},
22+
{
23+
"type": "inline",
24+
"tag": "",
25+
"attrs": null,
26+
"map": [
27+
0,
28+
1
29+
],
30+
"nesting": 0,
31+
"level": 1,
32+
"children": [
33+
{
34+
"type": "text",
35+
"tag": "",
36+
"attrs": null,
37+
"map": null,
38+
"nesting": 0,
39+
"level": 0,
40+
"children": null,
41+
"content": "Heading",
42+
"markup": "",
43+
"info": "",
44+
"meta": null,
45+
"block": false,
46+
"hidden": false,
47+
"lineNumber": 1,
48+
"line": "# Heading"
49+
}
50+
],
51+
"content": "Heading",
52+
"markup": "",
53+
"info": "",
54+
"meta": null,
55+
"block": true,
56+
"hidden": false,
57+
"line": "# Heading",
58+
"lineNumber": 1
59+
},
60+
{
61+
"type": "heading_close",
62+
"tag": "h1",
63+
"attrs": null,
64+
"map": null,
65+
"nesting": -1,
66+
"level": 0,
67+
"children": null,
68+
"content": "",
69+
"markup": "#",
70+
"info": "",
71+
"meta": null,
72+
"block": true,
73+
"hidden": false
74+
},
75+
{
76+
"type": "paragraph_open",
77+
"tag": "p",
78+
"attrs": null,
79+
"map": [
80+
2,
81+
3
82+
],
83+
"nesting": 1,
84+
"level": 0,
85+
"children": null,
86+
"content": "",
87+
"markup": "",
88+
"info": "",
89+
"meta": null,
90+
"block": true,
91+
"hidden": false,
92+
"line": "Text [ link ](https://example.com)",
93+
"lineNumber": 3
94+
},
95+
{
96+
"type": "inline",
97+
"tag": "",
98+
"attrs": null,
99+
"map": [
100+
2,
101+
3
102+
],
103+
"nesting": 0,
104+
"level": 1,
105+
"children": [
106+
{
107+
"type": "text",
108+
"tag": "",
109+
"attrs": null,
110+
"map": null,
111+
"nesting": 0,
112+
"level": 0,
113+
"children": null,
114+
"content": "Text",
115+
"markup": "",
116+
"info": "",
117+
"meta": null,
118+
"block": false,
119+
"hidden": false,
120+
"lineNumber": 3,
121+
"line": "Text [ link ](https://example.com)"
122+
},
123+
{
124+
"type": "link_open",
125+
"tag": "a",
126+
"attrs": [
127+
[
128+
"href",
129+
"https://example.com"
130+
]
131+
],
132+
"map": null,
133+
"nesting": 1,
134+
"level": 0,
135+
"children": null,
136+
"content": "",
137+
"markup": "",
138+
"info": "",
139+
"meta": null,
140+
"block": false,
141+
"hidden": false,
142+
"lineNumber": 3,
143+
"line": "Text [ link ](https://example.com)"
144+
},
145+
{
146+
"type": "text",
147+
"tag": "",
148+
"attrs": null,
149+
"map": null,
150+
"nesting": 0,
151+
"level": 1,
152+
"children": null,
153+
"content": "link",
154+
"markup": "",
155+
"info": "",
156+
"meta": null,
157+
"block": false,
158+
"hidden": false,
159+
"lineNumber": 3,
160+
"line": "Text [ link ](https://example.com)"
161+
},
162+
{
163+
"type": "link_close",
164+
"tag": "a",
165+
"attrs": null,
166+
"map": null,
167+
"nesting": -1,
168+
"level": 0,
169+
"children": null,
170+
"content": "",
171+
"markup": "",
172+
"info": "",
173+
"meta": null,
174+
"block": false,
175+
"hidden": false,
176+
"lineNumber": 3,
177+
"line": "Text [ link ](https://example.com)"
178+
}
179+
],
180+
"content": "Text [ link ](https://example.com)",
181+
"markup": "",
182+
"info": "",
183+
"meta": null,
184+
"block": true,
185+
"hidden": false,
186+
"line": "Text [ link ](https://example.com)",
187+
"lineNumber": 3
188+
},
189+
{
190+
"type": "paragraph_close",
191+
"tag": "p",
192+
"attrs": null,
193+
"map": null,
194+
"nesting": -1,
195+
"level": 0,
196+
"children": null,
197+
"content": "",
198+
"markup": "",
199+
"info": "",
200+
"meta": null,
201+
"block": true,
202+
"hidden": false
203+
}
204+
]

test/markdownItPlugins/file/.markdownlint-cli2.jsonc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"config": {
3+
"assert-markdown-it-tokens": {
4+
"file": "file.json"
5+
}
6+
},
7+
"customRules": [
8+
"../custom-rule-assert-markdown-it-tokens.mjs"
9+
],
210
"markdownItPlugins": [
311
[ "./custom-markdown-it-plugin.cjs" ]
412
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy