Skip to content

Commit e5275e3

Browse files
hendrikheilclaude
andauthored
fix(stringify): render ordered-list start as native numbering (#255)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e3c01c1 commit e5275e3

4 files changed

Lines changed: 114 additions & 1 deletion

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
## Input
2+
3+
```md
4+
::ol{start="3"}
5+
1. apple
6+
2. banana
7+
::
8+
```
9+
10+
## AST
11+
12+
```json
13+
{
14+
"frontmatter": {},
15+
"meta": {},
16+
"nodes": [
17+
[
18+
"ol",
19+
{
20+
"start": "3"
21+
},
22+
[
23+
"li",
24+
{},
25+
"apple"
26+
],
27+
[
28+
"li",
29+
{},
30+
"banana"
31+
]
32+
]
33+
]
34+
}
35+
```
36+
37+
## HTML
38+
39+
```html
40+
<ol start="3">
41+
<li>apple</li>
42+
<li>banana</li>
43+
</ol>
44+
```
45+
46+
## Markdown
47+
48+
```md
49+
3. apple
50+
4. banana
51+
```
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Input
2+
3+
```md
4+
5. First item
5+
6. Second item
6+
7. Third item
7+
```
8+
9+
## AST
10+
11+
```json
12+
{
13+
"frontmatter": {},
14+
"meta": {},
15+
"nodes": [
16+
[
17+
"ol",
18+
{
19+
"start": "5"
20+
},
21+
[
22+
"li",
23+
{},
24+
"First item"
25+
],
26+
[
27+
"li",
28+
{},
29+
"Second item"
30+
],
31+
[
32+
"li",
33+
{},
34+
"Third item"
35+
]
36+
]
37+
]
38+
}
39+
```
40+
41+
## HTML
42+
43+
```html
44+
<ol start="5">
45+
<li>First item</li>
46+
<li>Second item</li>
47+
<li>Third item</li>
48+
</ol>
49+
```
50+
51+
## Markdown
52+
53+
```md
54+
5. First item
55+
6. Second item
56+
7. Third item
57+
```

packages/comark/src/internal/stringify/attributes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export function resolveAttribute(attrs: Record<string, unknown>, renderData: Nod
9797
// is implicit in `- [ ]`) so they should not echo back as user attrs.
9898
const IMPLICIT_ATTRS: Record<string, { drop?: string[]; classBlocklist?: string[] }> = {
9999
blockquote: { drop: ['as'] },
100+
ol: { drop: ['start'] },
100101
ul: { classBlocklist: ['contains-task-list'] },
101102
li: { classBlocklist: ['task-list-item'] },
102103
// `language`/`filename`/`highlights`/`meta` ride on the fence info string.

packages/comark/src/internal/stringify/handlers/ol.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { comarkAttributes, userBlockAttrs } from '../attributes.ts'
66
export async function ol(node: ComarkElement, state: State) {
77
const children = node.slice(2) as ComarkNode[]
88

9-
const revert = state.applyContext({ list: true, order: 1, listIndent: 3 })
9+
// `start` is carried by the native numbering; IMPLICIT_ATTRS drops it from user attrs.
10+
const start = Number((node[1] as Record<string, unknown>).start)
11+
const order = Number.isInteger(start) && start >= 1 ? start : 1
12+
13+
const revert = state.applyContext({ list: true, order, listIndent: 3 })
1014

1115
let result = ''
1216
for (const child of children) {

0 commit comments

Comments
 (0)