Skip to content

Commit da8807c

Browse files
committed
refactor: better tree generation
1 parent 69c5e0c commit da8807c

111 files changed

Lines changed: 5789 additions & 4103 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ for await (const result of parseStreamIncremental(response.body!)) {
9191
if (!result.isComplete) {
9292
// Update UI as chunks arrive - auto-close ensures valid parsing!
9393
console.log(`Received chunk: ${result.chunk.length} bytes`)
94-
console.log(`Current elements: ${result.body.children.length}`)
94+
console.log(`Current elements: ${result.body.value.length}`)
9595
renderPartialContent(result.body)
9696
}
9797
else {
@@ -146,27 +146,27 @@ Parses MDC content incrementally, yielding results after each chunk.
146146

147147
```typescript
148148
interface ParseResult {
149-
body: MDCRoot // The parsed MDC AST
150-
excerpt?: MDCRoot // Optional excerpt (content before <!-- more -->)
149+
body: MinimarkTree // The parsed MDC AST
150+
excerpt?: MinimarkTree // Optional excerpt (content before <!-- more -->)
151151
data: any // Frontmatter data
152152
toc?: any // Table of contents
153153
}
154154

155155
interface IncrementalParseResult {
156156
chunk: string // The chunk just received
157-
body: MDCRoot // Current parsed state
157+
body: MinimarkTree // Current parsed state
158158
data: any // Frontmatter data (once available)
159159
isComplete: boolean // Whether stream is finished
160-
excerpt?: MDCRoot // Optional excerpt
160+
excerpt?: MinimarkTree // Optional excerpt
161161
toc?: any // TOC (only in final result)
162162
}
163163

164-
interface MDCRoot {
165-
type: 'root'
166-
children: MDCNode[]
164+
interface MinimarkTree {
165+
type: 'minimark'
166+
value: MinimarkNode[]
167167
}
168168

169-
interface MDCNode {
169+
interface MinimarkNode {
170170
type: 'element' | 'text' | 'comment'
171171
// ... additional properties based on type
172172
}

SPEC/GFM/table-aligned.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
timeout:
3+
parse: 5ms
4+
html: 5ms
5+
markdown: 5ms
6+
---
7+
8+
## Input
9+
10+
```md
11+
| Left-aligned | Center-aligned | Right-aligned |
12+
| :--- | :---: | ---: |
13+
| git status | git status | git status |
14+
| git diff | git diff | git diff |
15+
```
16+
17+
## AST
18+
19+
```json
20+
{
21+
"type": "minimark",
22+
"value": [
23+
[
24+
"table",
25+
{},
26+
[
27+
"thead",
28+
{},
29+
[
30+
"tr",
31+
{},
32+
[
33+
"th",
34+
{
35+
"style": "text-align:left"
36+
},
37+
"Left-aligned"
38+
],
39+
[
40+
"th",
41+
{
42+
"style": "text-align:center"
43+
},
44+
"Center-aligned"
45+
],
46+
[
47+
"th",
48+
{
49+
"style": "text-align:right"
50+
},
51+
"Right-aligned"
52+
]
53+
]
54+
],
55+
[
56+
"tbody",
57+
{},
58+
[
59+
"tr",
60+
{},
61+
[
62+
"td",
63+
{
64+
"style": "text-align:left"
65+
},
66+
"git status"
67+
],
68+
[
69+
"td",
70+
{
71+
"style": "text-align:center"
72+
},
73+
"git status"
74+
],
75+
[
76+
"td",
77+
{
78+
"style": "text-align:right"
79+
},
80+
"git status"
81+
]
82+
],
83+
[
84+
"tr",
85+
{},
86+
[
87+
"td",
88+
{
89+
"style": "text-align:left"
90+
},
91+
"git diff"
92+
],
93+
[
94+
"td",
95+
{
96+
"style": "text-align:center"
97+
},
98+
"git diff"
99+
],
100+
[
101+
"td",
102+
{
103+
"style": "text-align:right"
104+
},
105+
"git diff"
106+
]
107+
]
108+
]
109+
]
110+
]
111+
}
112+
```
113+
114+
## HTML
115+
116+
```html
117+
<table>
118+
<thead>
119+
<tr>
120+
<th style="text-align:left">Left-aligned</th>
121+
<th style="text-align:center">Center-aligned</th>
122+
<th style="text-align:right">Right-aligned</th>
123+
</tr>
124+
</thead>
125+
<tbody>
126+
<tr>
127+
<td style="text-align:left">git status</td>
128+
<td style="text-align:center">git status</td>
129+
<td style="text-align:right">git status</td>
130+
</tr>
131+
<tr>
132+
<td style="text-align:left">git diff</td>
133+
<td style="text-align:center">git diff</td>
134+
<td style="text-align:right">git diff</td>
135+
</tr>
136+
</tbody>
137+
</table>
138+
```
139+
140+
## Markdown
141+
142+
```md
143+
| Left-aligned | Center-aligned | Right-aligned |
144+
| :----------- | :------------: | ------------: |
145+
| git status | git status | git status |
146+
| git diff | git diff | git diff |
147+
```
148+
149+
150+
151+

SPEC/GFM/table-inline-markdown.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
timeout:
3+
parse: 5ms
4+
html: 5ms
5+
markdown: 5ms
6+
---
7+
8+
## Input
9+
10+
```md
11+
| Formatting | Example |
12+
|------------|---------|
13+
| **Bold** | `code` |
14+
| *Italic* | [link](url) |
15+
```
16+
17+
## AST
18+
19+
```json
20+
{
21+
"type": "minimark",
22+
"value": [
23+
[
24+
"table",
25+
{},
26+
[
27+
"thead",
28+
{},
29+
[
30+
"tr",
31+
{},
32+
[
33+
"th",
34+
{},
35+
"Formatting"
36+
],
37+
[
38+
"th",
39+
{},
40+
"Example"
41+
]
42+
]
43+
],
44+
[
45+
"tbody",
46+
{},
47+
[
48+
"tr",
49+
{},
50+
[
51+
"td",
52+
{},
53+
[
54+
"strong",
55+
{},
56+
"Bold"
57+
]
58+
],
59+
[
60+
"td",
61+
{},
62+
[
63+
"code",
64+
{},
65+
"code"
66+
]
67+
]
68+
],
69+
[
70+
"tr",
71+
{},
72+
[
73+
"td",
74+
{},
75+
[
76+
"em",
77+
{},
78+
"Italic"
79+
]
80+
],
81+
[
82+
"td",
83+
{},
84+
[
85+
"a",
86+
{
87+
"href": "url"
88+
},
89+
"link"
90+
]
91+
]
92+
]
93+
]
94+
]
95+
]
96+
}
97+
```
98+
99+
## HTML
100+
101+
```html
102+
<table>
103+
<thead>
104+
<tr>
105+
<th>Formatting</th>
106+
<th>Example</th>
107+
</tr>
108+
</thead>
109+
<tbody>
110+
<tr>
111+
<td><strong>Bold</strong></td>
112+
<td><code>code</code></td>
113+
</tr>
114+
<tr>
115+
<td><em>Italic</em></td>
116+
<td><a href="url">link</a></td>
117+
</tr>
118+
</tbody>
119+
</table>
120+
```
121+
122+
## Markdown
123+
124+
```md
125+
| Formatting | Example |
126+
| ---------- | ----------- |
127+
| **Bold** | `code` |
128+
| *Italic* | [link](url) |
129+
```

0 commit comments

Comments
 (0)