mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 07:05:44 +01:00
Answer stability round 1: tasksAsText takes the tasks and returns the items, numberedPastMarkers spells the bullets itself, the spec alternates bullet lists alone, and the migration row says the markers alternate
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ function migrateMarkdown(stored: string) {
|
|||||||
| the `adf` code fence and `:adf{json="…"}` | the `adf:<type>` code fence, its JSON without `type`, and `!adf:carry{json="…"}` |
|
| the `adf` code fence and `:adf{json="…"}` | the `adf:<type>` code fence, its JSON without `type`, and `!adf:carry{json="…"}` |
|
||||||
| `\:` keeps a directive literal | `\!adf:` keeps a directive literal |
|
| `\:` keeps a directive literal | `\!adf:` keeps a directive literal |
|
||||||
| `:adf{json="…"}` carrying a link for its `collection`, `id` or `occurrenceKey` | `!adf:link[text]{attrs}` |
|
| `:adf{json="…"}` carrying a link for its `collection`, `id` or `occurrenceKey` | `!adf:link[text]{attrs}` |
|
||||||
| `::listBreak` between two lists of a kind | no separator, the second list's marker changed: `* ` for `- `, `1)` for `1.` |
|
| `::listBreak` between two lists of a kind | no separator, the second list's marker changed: `* ` for `- `, `1)` for `1.`, alternating |
|
||||||
|
|
||||||
A colon run and `:name[` are plain text now, and `adf` an ordinary code block language; text
|
A colon run and `:name[` are plain text now, and `adf` an ordinary code block language; text
|
||||||
holding an unescaped `!adf:` and a code fence whose info string opens `adf:` are claimed instead.
|
holding an unescaped `!adf:` and a code fence whose info string opens `adf:` are claimed instead.
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ normalizes to it through the round-trip.
|
|||||||
single tilde or a run of three or more is literal text — and block structure resolves before
|
single tilde or a run of three or more is literal text — and block structure resolves before
|
||||||
inline, so a `~~~` line opens a CommonMark tilde code fence.
|
inline, so a `~~~` line opens a CommonMark tilde code fence.
|
||||||
- Bullet lists `- `; ordered lists incrementing `1.` `2.` `3.`, the first number the node's
|
- Bullet lists `- `; ordered lists incrementing `1.` `2.` `3.`, the first number the node's
|
||||||
`order` attribute. A bullet or task list right after a bullet or task list takes `* `, and an
|
`order` attribute. A bullet list right after a bullet list takes `* `, and an ordered list
|
||||||
ordered list right after an ordered one `1)`, since CommonMark starts a new list where the
|
right after an ordered one `1)`, since CommonMark starts a new list where the
|
||||||
bullet character or the delimiter changes; the list after that takes `- ` or `1.` again. An item
|
bullet character or the delimiter changes; the list after that takes `- ` or `1.` again. An item
|
||||||
text of asterisks and spaces that would read as a rule after `* ` opens with a backslash,
|
text of asterisks and spaces that would read as a rule after `* ` opens with a backslash,
|
||||||
`* \**`. Continuation lines align with the first character
|
`* \**`. Continuation lines align with the first character
|
||||||
|
|||||||
@@ -136,23 +136,17 @@ function portableSequence(blocks: readonly AdfNode[], reduction: Reduction): Res
|
|||||||
function numberedPastMarkers(list: AdfNode): AdfNode {
|
function numberedPastMarkers(list: AdfNode): AdfNode {
|
||||||
const order = nodeAttrs(list)['order']
|
const order = nodeAttrs(list)['order']
|
||||||
if (list.type !== 'orderedList' || typeof order !== 'number' || order + nodeContent(list).length - 1 <= largestListMarker) return list
|
if (list.type !== 'orderedList' || typeof order !== 'number' || order + nodeContent(list).length - 1 <= largestListMarker) return list
|
||||||
return numberedAsText(list)
|
|
||||||
}
|
|
||||||
|
|
||||||
function numberedAsText(list: AdfNode): AdfNode {
|
|
||||||
const order = Number(nodeAttrs(list)['order'])
|
|
||||||
return { content: nodeContent(list).map((item, offset) => itemOf(marked(nodeContent(item), `${order + offset}.`))), type: 'bulletList' }
|
return { content: nodeContent(list).map((item, offset) => itemOf(marked(nodeContent(item), `${order + offset}.`))), type: 'bulletList' }
|
||||||
}
|
}
|
||||||
|
|
||||||
// A task keeps its marker as text; a list item stands as one, and anything else nests in the item before it.
|
// A task keeps its marker as text; a list item stands as one, and anything else nests in the item before it.
|
||||||
function tasksAsText(list: AdfNode): AdfNode {
|
function tasksAsText(tasks: readonly AdfNode[]): AdfNode[] {
|
||||||
if (list.type !== 'taskList') return list
|
|
||||||
const items: AdfNode[] = []
|
const items: AdfNode[] = []
|
||||||
for (const child of nodeContent(list)) {
|
for (const child of tasks) {
|
||||||
const previous = isTaskItem(child) || child.type === 'listItem' ? undefined : items.pop()
|
const previous = isTaskItem(child) || child.type === 'listItem' ? undefined : items.pop()
|
||||||
items.push(itemOf(previous === undefined ? taskAsText(child) : [...nodeContent(previous), child]))
|
items.push(itemOf(previous === undefined ? taskAsText(child) : [...nodeContent(previous), child]))
|
||||||
}
|
}
|
||||||
return { content: items, type: 'bulletList' }
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
function taskAsText(child: AdfNode): readonly AdfNode[] {
|
function taskAsText(child: AdfNode): readonly AdfNode[] {
|
||||||
@@ -271,7 +265,7 @@ function reduceTaskList(node: AdfNode, reduction: Reduction): Result<AdfNode[]>
|
|||||||
for (const block of standsAlone ? [{ content: blocks, type: 'listItem' }] : blocks) tasks.push(block)
|
for (const block of standsAlone ? [{ content: blocks, type: 'listItem' }] : blocks) tasks.push(block)
|
||||||
}
|
}
|
||||||
if (regular) return success(splitTaskList({ content: tasks, type: 'taskList' }))
|
if (regular) return success(splitTaskList({ content: tasks, type: 'taskList' }))
|
||||||
return success(listOf(nodeContent(tasksAsText({ content: tasks, type: 'taskList' })), 'bulletList'))
|
return success(listOf(tasksAsText(tasks), 'bulletList'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function reduceTask(task: AdfNode, at: Reduction): Result<AdfNode[]> {
|
function reduceTask(task: AdfNode, at: Reduction): Result<AdfNode[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user