Skip to content

Commit af202d3

Browse files
committed
Fix start on ordered lists in mdast
Closes GH-38.
1 parent a8f5da1 commit af202d3

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

Untitled.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ micromark.js: `atLineEnding` in html (text) should always eat arbitrary whitespa
66
```rs
77
// ---------------------
88
// Useful helper:
9+
extern crate std;
910
use std::println;
1011
use alloc::string::String;
1112

src/to_mdast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,9 @@ fn on_exit_list_item_value(context: &mut CompileContext) {
14301430

14311431
if let Node::List(node) = context.tail_penultimate_mut() {
14321432
debug_assert!(node.ordered, "expected list to be ordered");
1433-
node.start = Some(start);
1433+
if node.start.is_none() {
1434+
node.start = Some(start);
1435+
}
14341436
} else {
14351437
unreachable!("expected list on stack");
14361438
}

tests/list.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -616,27 +616,41 @@ fn list() -> Result<(), String> {
616616
);
617617

618618
assert_eq!(
619-
to_mdast("3. a", &Default::default())?,
619+
to_mdast("3. a\n4. b", &Default::default())?,
620620
Node::Root(Root {
621621
children: vec![Node::List(List {
622622
ordered: true,
623623
spread: false,
624624
start: Some(3),
625-
children: vec![Node::ListItem(ListItem {
626-
checked: None,
627-
spread: false,
628-
children: vec![Node::Paragraph(Paragraph {
629-
children: vec![Node::Text(Text {
630-
value: "a".into(),
625+
children: vec![
626+
Node::ListItem(ListItem {
627+
checked: None,
628+
spread: false,
629+
children: vec![Node::Paragraph(Paragraph {
630+
children: vec![Node::Text(Text {
631+
value: "a".into(),
632+
position: Some(Position::new(1, 4, 3, 1, 5, 4))
633+
}),],
631634
position: Some(Position::new(1, 4, 3, 1, 5, 4))
632-
}),],
633-
position: Some(Position::new(1, 4, 3, 1, 5, 4))
634-
})],
635-
position: Some(Position::new(1, 1, 0, 1, 5, 4))
636-
})],
637-
position: Some(Position::new(1, 1, 0, 1, 5, 4))
635+
})],
636+
position: Some(Position::new(1, 1, 0, 1, 5, 4))
637+
}),
638+
Node::ListItem(ListItem {
639+
checked: None,
640+
spread: false,
641+
children: vec![Node::Paragraph(Paragraph {
642+
children: vec![Node::Text(Text {
643+
value: "b".into(),
644+
position: Some(Position::new(2, 4, 8, 2, 5, 9))
645+
}),],
646+
position: Some(Position::new(2, 4, 8, 2, 5, 9))
647+
})],
648+
position: Some(Position::new(2, 1, 5, 2, 5, 9))
649+
})
650+
],
651+
position: Some(Position::new(1, 1, 0, 2, 5, 9))
638652
})],
639-
position: Some(Position::new(1, 1, 0, 1, 5, 4))
653+
position: Some(Position::new(1, 1, 0, 2, 5, 9))
640654
}),
641655
"should support `start` fields on `List` w/ `ordered: true` in mdast"
642656
);

0 commit comments

Comments
 (0)