Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
## Input

```md
::ol{start="3"}
1. apple
2. banana
::
```

## AST

```json
{
"frontmatter": {},
"meta": {},
"nodes": [
[
"ol",
{
"start": "3"
},
[
"li",
{},
"apple"
],
[
"li",
{},
"banana"
]
]
]
}
```

## HTML

```html
<ol start="3">
<li>apple</li>
<li>banana</li>
</ol>
```

## Markdown

```md
3. apple
4. banana
```
57 changes: 57 additions & 0 deletions packages/comark/SPEC/common-mark/ordered-list-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Input

```md
5. First item
6. Second item
7. Third item
```

## AST

```json
{
"frontmatter": {},
"meta": {},
"nodes": [
[
"ol",
{
"start": "5"
},
[
"li",
{},
"First item"
],
[
"li",
{},
"Second item"
],
[
"li",
{},
"Third item"
]
]
]
}
```

## HTML

```html
<ol start="5">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
```

## Markdown

```md
5. First item
6. Second item
7. Third item
```
1 change: 1 addition & 0 deletions packages/comark/src/internal/stringify/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function resolveAttribute(attrs: Record<string, unknown>, renderData: Nod
// is implicit in `- [ ]`) so they should not echo back as user attrs.
const IMPLICIT_ATTRS: Record<string, { drop?: string[]; classBlocklist?: string[] }> = {
blockquote: { drop: ['as'] },
ol: { drop: ['start'] },
ul: { classBlocklist: ['contains-task-list'] },
li: { classBlocklist: ['task-list-item'] },
// `language`/`filename`/`highlights`/`meta` ride on the fence info string.
Expand Down
6 changes: 5 additions & 1 deletion packages/comark/src/internal/stringify/handlers/ol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { comarkAttributes, userBlockAttrs } from '../attributes.ts'
export async function ol(node: ComarkElement, state: State) {
const children = node.slice(2) as ComarkNode[]

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

const revert = state.applyContext({ list: true, order, listIndent: 3 })

let result = ''
for (const child of children) {
Expand Down
Loading