Skip to content

Commit bbb4301

Browse files
authored
fix(syntax): thematic breaks in component slots (#184)
1 parent 78c2e66 commit bbb4301

3 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## Input
2+
3+
```md
4+
::card
5+
#description
6+
Line one
7+
8+
---
9+
10+
Middle line
11+
12+
---
13+
14+
Line three
15+
::
16+
```
17+
18+
## AST
19+
20+
```json
21+
{
22+
"frontmatter": {},
23+
"meta": {},
24+
"nodes": [
25+
[
26+
"card",
27+
{},
28+
[
29+
"template",
30+
{ "name": "description" },
31+
["p", {}, "Line one"],
32+
["hr", {}],
33+
["p", {}, "Middle line"],
34+
["hr", {}],
35+
["p", {}, "Line three"]
36+
]
37+
]
38+
]
39+
}
40+
```
41+
42+
## HTML
43+
44+
```html
45+
<card>
46+
<template name="description">
47+
<p>Line one</p>
48+
<hr />
49+
<p>Middle line</p>
50+
<hr />
51+
<p>Line three</p>
52+
</template>
53+
</card>
54+
```
55+
56+
## Markdown
57+
58+
```md
59+
::card
60+
#description
61+
Line one
62+
63+
---
64+
65+
Middle line
66+
67+
---
68+
69+
Line three
70+
::
71+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Input
2+
3+
```md
4+
::card
5+
Above
6+
7+
---
8+
9+
Middle text
10+
11+
---
12+
13+
Below
14+
::
15+
```
16+
17+
## AST
18+
19+
```json
20+
{
21+
"frontmatter": {},
22+
"meta": {},
23+
"nodes": [
24+
[
25+
"card",
26+
{},
27+
["p", {}, "Above"],
28+
["hr", {}],
29+
["p", {}, "Middle text"],
30+
["hr", {}],
31+
["p", {}, "Below"]
32+
]
33+
]
34+
}
35+
```
36+
37+
## HTML
38+
39+
```html
40+
<card>
41+
<p>Above</p>
42+
<hr />
43+
<p>Middle text</p>
44+
<hr />
45+
<p>Below</p>
46+
</card>
47+
```
48+
49+
## Markdown
50+
51+
```md
52+
::card
53+
Above
54+
55+
---
56+
57+
Middle text
58+
59+
---
60+
61+
Below
62+
::
63+
```

packages/comark/src/plugins/syntax.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ const markdownItComarkBlock: PluginSimple = (md) => {
283283

284284
if (!blockAttributesClosingFence) return false
285285

286+
// The `---` fence is only valid on the line immediately after the component opener. Any other `---` is a thematic break.
287+
if (line === '---') {
288+
const parentOpenLine = state.env.comarkBlockTokens[0].map?.[0]
289+
if (parentOpenLine === undefined || startLine !== parentOpenLine + 1) return false
290+
}
291+
286292
let lineEnd = startLine + 1
287293
let found = false
288294
while (lineEnd < endLine) {

0 commit comments

Comments
 (0)