Keep numbered lists counting across nested items and blank lines
A list ended at the first line that was not an item, so a numbered list with nested bullets, wrapped lines or blank lines between items became one-item lists that each showed 1. Lists now nest (an item holds the blocks indented under it), continue across blank lines, join wrapped lines, and number from their first item. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -102,10 +102,10 @@ void main() {
|
||||
expect((blocks[0] as MarkdownQuote).lines, ['quoted **line**', 'second']);
|
||||
final bullets = blocks[1] as MarkdownList;
|
||||
expect(bullets.ordered, isFalse);
|
||||
expect(bullets.items, ['one', 'two']);
|
||||
expect(_texts(bullets), ['one', 'two']);
|
||||
final ordered = blocks[2] as MarkdownList;
|
||||
expect(ordered.ordered, isTrue);
|
||||
expect(ordered.items, ['first', 'second']);
|
||||
expect(_texts(ordered), ['first', 'second']);
|
||||
});
|
||||
|
||||
test('thematic rules need three identical markers', () {
|
||||
@@ -198,11 +198,66 @@ void main() {
|
||||
expect(_visible(parseInline(source)), source);
|
||||
});
|
||||
|
||||
test('an indented nested item is retained rather than dropped', () {
|
||||
test('an indented nested item is kept under its parent', () {
|
||||
final blocks = parseMarkdown('- outer\n - inner\n continuation');
|
||||
final list = blocks.first as MarkdownList;
|
||||
expect(list.items, ['outer', 'inner']);
|
||||
expect((blocks.last as MarkdownParagraph).text, 'continuation');
|
||||
final list = blocks.single as MarkdownList;
|
||||
expect(_texts(list), ['outer']);
|
||||
final inner = list.items.single.children.single as MarkdownList;
|
||||
expect(_texts(inner), ['inner continuation']);
|
||||
});
|
||||
|
||||
test('numbered items keep counting around nested bullets', () {
|
||||
final blocks = parseMarkdown(
|
||||
'1. First\n - detail a\n - detail b\n2. Second\n - detail c\n'
|
||||
'3. Third',
|
||||
);
|
||||
final list = blocks.single as MarkdownList;
|
||||
expect(list.ordered, isTrue);
|
||||
expect(_texts(list), ['First', 'Second', 'Third']);
|
||||
expect(_texts(list.items.first.children.single as MarkdownList), [
|
||||
'detail a',
|
||||
'detail b',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a loose list stays one list across blank lines', () {
|
||||
final list =
|
||||
parseMarkdown('1. one\n\n2. two\n\n\n3. three').single
|
||||
as MarkdownList;
|
||||
expect(_texts(list), ['one', 'two', 'three']);
|
||||
});
|
||||
|
||||
test('an ordered list starts at its first number', () {
|
||||
final list = parseMarkdown('3. three\n4. four').single as MarkdownList;
|
||||
expect(list.start, 3);
|
||||
expect(parseMarkdown('- a').single, isA<MarkdownList>());
|
||||
});
|
||||
|
||||
test('a wrapped line and an indented paragraph stay in their item', () {
|
||||
final list =
|
||||
parseMarkdown(
|
||||
'1. starts here\nand wraps\n\n later paragraph\n2. next',
|
||||
).single
|
||||
as MarkdownList;
|
||||
expect(_texts(list), ['starts here and wraps', 'next']);
|
||||
expect(
|
||||
(list.items.first.children.single as MarkdownParagraph).text,
|
||||
'later paragraph',
|
||||
);
|
||||
});
|
||||
|
||||
test('a list ends at text back at the margin after a blank line', () {
|
||||
final blocks = parseMarkdown('1. one\n2. two\n\nAfter the list.');
|
||||
expect(blocks, hasLength(2));
|
||||
expect((blocks.last as MarkdownParagraph).text, 'After the list.');
|
||||
});
|
||||
|
||||
test('nested content is decoded once', () {
|
||||
final list =
|
||||
parseMarkdown('- a\n - &lt;b&gt;').single as MarkdownList;
|
||||
expect(_texts(list.items.single.children.single as MarkdownList), [
|
||||
'<b>',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a link with an empty target stays literal', () {
|
||||
@@ -212,3 +267,7 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
List<String> _texts(MarkdownList list) => [
|
||||
for (final item in list.items) item.text,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user