diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-12-19 09:58:52 +0400 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-12-19 09:58:52 +0400 |
commit | af202d3f0ea24e0a957b02a6f9fb23c6c3b4afe7 (patch) | |
tree | 2b17565298b591fab613c53924b47ec66b870b81 | |
parent | a8f5da1524761c5f55deca36c34ff8aee061bf32 (diff) | |
download | markdown-rs-af202d3f0ea24e0a957b02a6f9fb23c6c3b4afe7.tar.gz markdown-rs-af202d3f0ea24e0a957b02a6f9fb23c6c3b4afe7.tar.bz2 markdown-rs-af202d3f0ea24e0a957b02a6f9fb23c6c3b4afe7.zip |
Fix `start` on ordered lists in mdast
Closes GH-38.
Diffstat (limited to '')
-rw-r--r-- | Untitled.txt | 1 | ||||
-rw-r--r-- | src/to_mdast.rs | 4 | ||||
-rw-r--r-- | tests/list.rs | 42 |
3 files changed, 32 insertions, 15 deletions
diff --git a/Untitled.txt b/Untitled.txt index 90e2f5e..fb1e53c 100644 --- a/Untitled.txt +++ b/Untitled.txt @@ -6,6 +6,7 @@ micromark.js: `atLineEnding` in html (text) should always eat arbitrary whitespa ```rs // --------------------- // Useful helper: +extern crate std; use std::println; use alloc::string::String; diff --git a/src/to_mdast.rs b/src/to_mdast.rs index 4d2ca76..e76bad5 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -1430,7 +1430,9 @@ fn on_exit_list_item_value(context: &mut CompileContext) { if let Node::List(node) = context.tail_penultimate_mut() { debug_assert!(node.ordered, "expected list to be ordered"); - node.start = Some(start); + if node.start.is_none() { + node.start = Some(start); + } } else { unreachable!("expected list on stack"); } diff --git a/tests/list.rs b/tests/list.rs index e8c42e8..0c2992e 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -616,27 +616,41 @@ fn list() -> Result<(), String> { ); assert_eq!( - to_mdast("3. a", &Default::default())?, + to_mdast("3. a\n4. b", &Default::default())?, Node::Root(Root { children: vec![Node::List(List { ordered: true, spread: false, start: Some(3), - children: vec![Node::ListItem(ListItem { - checked: None, - spread: false, - children: vec![Node::Paragraph(Paragraph { - children: vec![Node::Text(Text { - value: "a".into(), + children: vec![ + Node::ListItem(ListItem { + checked: None, + spread: false, + children: vec![Node::Paragraph(Paragraph { + children: vec![Node::Text(Text { + value: "a".into(), + position: Some(Position::new(1, 4, 3, 1, 5, 4)) + }),], position: Some(Position::new(1, 4, 3, 1, 5, 4)) - }),], - position: Some(Position::new(1, 4, 3, 1, 5, 4)) - })], - position: Some(Position::new(1, 1, 0, 1, 5, 4)) - })], - position: Some(Position::new(1, 1, 0, 1, 5, 4)) + })], + position: Some(Position::new(1, 1, 0, 1, 5, 4)) + }), + Node::ListItem(ListItem { + checked: None, + spread: false, + children: vec![Node::Paragraph(Paragraph { + children: vec![Node::Text(Text { + value: "b".into(), + position: Some(Position::new(2, 4, 8, 2, 5, 9)) + }),], + position: Some(Position::new(2, 4, 8, 2, 5, 9)) + })], + position: Some(Position::new(2, 1, 5, 2, 5, 9)) + }) + ], + position: Some(Position::new(1, 1, 0, 2, 5, 9)) })], - position: Some(Position::new(1, 1, 0, 1, 5, 4)) + position: Some(Position::new(1, 1, 0, 2, 5, 9)) }), "should support `start` fields on `List` w/ `ordered: true` in mdast" ); |