fix: parse ::directives correctly (#41186)
This commit is contained in:
committed by
GitHub
parent
b12360d4a8
commit
04c2f4e620
185
tools/challenge-parser/parser/__fixtures__/ast-directives.json
Normal file
185
tools/challenge-parser/parser/__fixtures__/ast-directives.json
Normal file
@ -0,0 +1,185 @@
|
||||
{
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--description--",
|
||||
"position": {
|
||||
"start": { "line": 1, "column": 3, "offset": 2 },
|
||||
"end": { "line": 1, "column": 18, "offset": 17 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 1, "column": 1, "offset": 0 },
|
||||
"end": { "line": 1, "column": 18, "offset": 17 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "textDirective",
|
||||
"name": "root",
|
||||
"attributes": {},
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 1, "offset": 19 },
|
||||
"end": { "line": 3, "column": 6, "offset": 24 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": " appears, ",
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 6, "offset": 24 },
|
||||
"end": { "line": 3, "column": 16, "offset": 34 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "textDirective",
|
||||
"name": "import",
|
||||
"attributes": {},
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 16, "offset": 34 },
|
||||
"end": { "line": 3, "column": 23, "offset": 41 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": " appears",
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 23, "offset": 41 },
|
||||
"end": { "line": 3, "column": 31, "offset": 49 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 1, "offset": 19 },
|
||||
"end": { "line": 3, "column": 31, "offset": 49 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "the next paragraph should appear",
|
||||
"position": {
|
||||
"start": { "line": 5, "column": 1, "offset": 51 },
|
||||
"end": { "line": 5, "column": 33, "offset": 83 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 5, "column": 1, "offset": 51 },
|
||||
"end": { "line": 5, "column": 33, "offset": 83 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "import",
|
||||
"attributes": {},
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 7, "column": 1, "offset": 85 },
|
||||
"end": { "line": 7, "column": 9, "offset": 93 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "even though it's an import directive, but if we use the full syntax ",
|
||||
"position": {
|
||||
"start": { "line": 9, "column": 1, "offset": 95 },
|
||||
"end": { "line": 9, "column": 58, "offset": 152 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "inlineCode",
|
||||
"value": "::directive-name{attr=\"name\" attr2=\"a/path\"}",
|
||||
"position": {
|
||||
"start": { "line": 9, "column": 58, "offset": 152 },
|
||||
"end": { "line": 9, "column": 100, "offset": 194 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 9, "column": 1, "offset": 95 },
|
||||
"end": { "line": 9, "column": 100, "offset": 194 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "import",
|
||||
"attributes": { "component": "name", "from": "script.md" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 11, "column": 1, "offset": 196 },
|
||||
"end": { "line": 11, "column": 44, "offset": 239 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "it goes.",
|
||||
"position": {
|
||||
"start": { "line": 13, "column": 1, "offset": 241 },
|
||||
"end": { "line": 13, "column": 9, "offset": 249 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 13, "column": 1, "offset": 241 },
|
||||
"end": { "line": 13, "column": 9, "offset": 249 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "::: name [inline-content] {key=val}\na container directive\n:::",
|
||||
"position": {
|
||||
"start": { "line": 15, "column": 1, "offset": 251 },
|
||||
"end": { "line": 17, "column": 4, "offset": 312 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 15, "column": 1, "offset": 251 },
|
||||
"end": { "line": 17, "column": 4, "offset": 312 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": ":::",
|
||||
"position": {
|
||||
"start": { "line": 19, "column": 1, "offset": 314 },
|
||||
"end": { "line": 19, "column": 4, "offset": 317 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 19, "column": 1, "offset": 314 },
|
||||
"end": { "line": 19, "column": 4, "offset": 317 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 1, "column": 1, "offset": 0 },
|
||||
"end": { "line": 20, "column": 1, "offset": 318 }
|
||||
}
|
||||
}
|
@ -0,0 +1,321 @@
|
||||
{
|
||||
"type": "root",
|
||||
"children": [
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "import",
|
||||
"attributes": { "component": "Script", "from": "./script.md" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 1, "column": 1, "offset": 0 },
|
||||
"end": { "line": 1, "column": 49, "offset": 48 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "import",
|
||||
"attributes": { "component": "Second", "from": "./script-two.md" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 2, "column": 1, "offset": 49 },
|
||||
"end": { "line": 2, "column": 53, "offset": 101 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "import",
|
||||
"attributes": {},
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 3, "column": 1, "offset": 102 },
|
||||
"end": { "line": 3, "column": 9, "offset": 110 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--description--",
|
||||
"position": {
|
||||
"start": { "line": 5, "column": 3, "offset": 114 },
|
||||
"end": { "line": 5, "column": 18, "offset": 129 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 5, "column": 1, "offset": 112 },
|
||||
"end": { "line": 5, "column": 18, "offset": 129 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Paragraph 1 ::import",
|
||||
"position": {
|
||||
"start": { "line": 7, "column": 1, "offset": 131 },
|
||||
"end": { "line": 7, "column": 21, "offset": 151 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 7, "column": 1, "offset": 131 },
|
||||
"end": { "line": 7, "column": 21, "offset": 151 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "html",
|
||||
"meta": null,
|
||||
"value": "code example",
|
||||
"position": {
|
||||
"start": { "line": 9, "column": 1, "offset": 153 },
|
||||
"end": { "line": 11, "column": 4, "offset": 177 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--instructions--",
|
||||
"position": {
|
||||
"start": { "line": 13, "column": 3, "offset": 181 },
|
||||
"end": { "line": 13, "column": 19, "offset": 197 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 13, "column": 1, "offset": 179 },
|
||||
"end": { "line": 13, "column": 19, "offset": 197 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Paragraph 0",
|
||||
"position": {
|
||||
"start": { "line": 15, "column": 1, "offset": 199 },
|
||||
"end": { "line": 15, "column": 12, "offset": 210 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 15, "column": 1, "offset": 199 },
|
||||
"end": { "line": 15, "column": 12, "offset": 210 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "html",
|
||||
"meta": null,
|
||||
"value": "code example 0",
|
||||
"position": {
|
||||
"start": { "line": 17, "column": 1, "offset": 212 },
|
||||
"end": { "line": 19, "column": 4, "offset": 238 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--hints--",
|
||||
"position": {
|
||||
"start": { "line": 21, "column": 3, "offset": 242 },
|
||||
"end": { "line": 21, "column": 12, "offset": 251 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 21, "column": 1, "offset": 240 },
|
||||
"end": { "line": 21, "column": 12, "offset": 251 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "First hint",
|
||||
"position": {
|
||||
"start": { "line": 23, "column": 1, "offset": 253 },
|
||||
"end": { "line": 23, "column": 11, "offset": 263 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 23, "column": 1, "offset": 253 },
|
||||
"end": { "line": 23, "column": 11, "offset": 263 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "js",
|
||||
"meta": null,
|
||||
"value": "// test code",
|
||||
"position": {
|
||||
"start": { "line": 25, "column": 1, "offset": 265 },
|
||||
"end": { "line": 27, "column": 4, "offset": 287 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "paragraph",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Second hint with ",
|
||||
"position": {
|
||||
"start": { "line": 29, "column": 1, "offset": 289 },
|
||||
"end": { "line": 29, "column": 18, "offset": 306 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "html",
|
||||
"value": "<code>",
|
||||
"position": {
|
||||
"start": { "line": 29, "column": 18, "offset": 306 },
|
||||
"end": { "line": 29, "column": 24, "offset": 312 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"value": "code",
|
||||
"position": {
|
||||
"start": { "line": 29, "column": 24, "offset": 312 },
|
||||
"end": { "line": 29, "column": 28, "offset": 316 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "html",
|
||||
"value": "</code>",
|
||||
"position": {
|
||||
"start": { "line": 29, "column": 28, "offset": 316 },
|
||||
"end": { "line": 29, "column": 35, "offset": 323 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 29, "column": 1, "offset": 289 },
|
||||
"end": { "line": 29, "column": 35, "offset": 323 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "js",
|
||||
"meta": null,
|
||||
"value": "// more test code",
|
||||
"position": {
|
||||
"start": { "line": 31, "column": 1, "offset": 325 },
|
||||
"end": { "line": 33, "column": 4, "offset": 352 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 1,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--seed--",
|
||||
"position": {
|
||||
"start": { "line": 36, "column": 3, "offset": 357 },
|
||||
"end": { "line": 36, "column": 11, "offset": 365 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 36, "column": 1, "offset": 355 },
|
||||
"end": { "line": 36, "column": 11, "offset": 365 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "heading",
|
||||
"depth": 2,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "--seed-contents--",
|
||||
"position": {
|
||||
"start": { "line": 38, "column": 4, "offset": 370 },
|
||||
"end": { "line": 38, "column": 21, "offset": 387 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 38, "column": 1, "offset": 367 },
|
||||
"end": { "line": 38, "column": 21, "offset": 387 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "html",
|
||||
"meta": null,
|
||||
"value": "<html>\n <body>\n </body>\n</html>",
|
||||
"position": {
|
||||
"start": { "line": 40, "column": 1, "offset": 389 },
|
||||
"end": { "line": 45, "column": 4, "offset": 434 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "css",
|
||||
"meta": null,
|
||||
"value": "body {\n background: green;\n}",
|
||||
"position": {
|
||||
"start": { "line": 47, "column": 1, "offset": 436 },
|
||||
"end": { "line": 51, "column": 4, "offset": 476 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "use",
|
||||
"attributes": { "component": "Second" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 53, "column": 1, "offset": 478 },
|
||||
"end": { "line": 53, "column": 26, "offset": 503 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "id",
|
||||
"attributes": { "id": "custom-name" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 55, "column": 1, "offset": 505 },
|
||||
"end": { "line": 55, "column": 19, "offset": 523 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "code",
|
||||
"lang": "js",
|
||||
"meta": null,
|
||||
"value": "var x = 'y';",
|
||||
"position": {
|
||||
"start": { "line": 57, "column": 1, "offset": 525 },
|
||||
"end": { "line": 59, "column": 4, "offset": 547 }
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "leafDirective",
|
||||
"name": "use",
|
||||
"attributes": { "component": "Script" },
|
||||
"children": [],
|
||||
"position": {
|
||||
"start": { "line": 61, "column": 1, "offset": 549 },
|
||||
"end": { "line": 61, "column": 26, "offset": 574 }
|
||||
}
|
||||
}
|
||||
],
|
||||
"position": {
|
||||
"start": { "line": 1, "column": 1, "offset": 0 },
|
||||
"end": { "line": 62, "column": 1, "offset": 575 }
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
# --description--
|
||||
|
||||
:root appears, :import appears
|
||||
|
||||
the next paragraph should appear
|
||||
|
||||
::import
|
||||
|
||||
even though it's an import directive, but if we use the full syntax `::directive-name{attr="name" attr2="a/path"}`
|
||||
|
||||
::import{component="name" from="script.md"}
|
||||
|
||||
it goes.
|
||||
|
||||
::: name [inline-content] {key=val}
|
||||
a container directive
|
||||
:::
|
@ -0,0 +1,61 @@
|
||||
::import{component="Script" from="./script.md" }
|
||||
::import{component="Second" from="./script-two.md" }
|
||||
::import
|
||||
|
||||
# --description--
|
||||
|
||||
Paragraph 1 ::import
|
||||
|
||||
```html
|
||||
code example
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
Paragraph 0
|
||||
|
||||
```html
|
||||
code example 0
|
||||
```
|
||||
|
||||
# --hints--
|
||||
|
||||
First hint
|
||||
|
||||
```js
|
||||
// test code
|
||||
```
|
||||
|
||||
Second hint with <code>code</code>
|
||||
|
||||
```js
|
||||
// more test code
|
||||
```
|
||||
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```css
|
||||
body {
|
||||
background: green;
|
||||
}
|
||||
```
|
||||
|
||||
::use{component="Second"}
|
||||
|
||||
::id{#custom-name}
|
||||
|
||||
```js
|
||||
var x = 'y';
|
||||
```
|
||||
|
||||
::use{component="Script"}
|
Reference in New Issue
Block a user