diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs
index d1dbe881..856852bf 100644
--- a/src/interpreter/mod.rs
+++ b/src/interpreter/mod.rs
@@ -504,24 +504,20 @@ impl TokenSink for HtmlInterpreter {
for element in self.state.element_stack.iter_mut().rev() {
if let html::Element::List(html_list) = element {
list = Some(html_list);
+ break;
}
}
let list = list.expect("List ended unexpectedly");
if self.current_textbox.texts.is_empty() {
- if let html::List {
- list_type: html::ListType::Ordered(index),
- ..
- } = list
- {
- self.state.pending_list_prefix = Some(format!("{}. ", index));
- *index += 1;
- } else if let html::List {
- list_type: html::ListType::Unordered,
- ..
- } = list
- {
- self.state.pending_list_prefix = Some("· ".to_owned());
- }
+ let prefix = match &mut list.list_type {
+ html::ListType::Ordered(index) => {
+ *index += 1;
+ format!("{}. ", *index - 1)
+ }
+ html::ListType::Unordered => "· ".to_owned(),
+ };
+
+ self.state.pending_list_prefix = Some(prefix);
}
}
"ul" => {
diff --git a/src/interpreter/snapshots/inlyne__interpreter__tests__nested_ordered_list.snap b/src/interpreter/snapshots/inlyne__interpreter__tests__nested_ordered_list.snap
new file mode 100644
index 00000000..068e4880
--- /dev/null
+++ b/src/interpreter/snapshots/inlyne__interpreter__tests__nested_ordered_list.snap
@@ -0,0 +1,72 @@
+---
+source: src/interpreter/tests.rs
+description: " --- md\n\n1. 1st outer\n 1. 1st inner\n2. 2nd outer\n\n\n --- html\n\n
\n- 1st outer\n
\n- 1st inner
\n
\n \n- 2nd outer
\n
\n"
+expression: interpret_md(text)
+---
+[
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "1. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "1st outer",
+ default_color: Color(BLACK),
+ ..
+ },
+ Text {
+ text: " ",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 100.0,
+ texts: [
+ Text {
+ text: "1. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "1st inner",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "2. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "2nd outer",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ Spacer(
+ InvisibleSpacer(5),
+ ),
+]
diff --git a/src/interpreter/snapshots/inlyne__interpreter__tests__ordered_list_in_unordered.snap b/src/interpreter/snapshots/inlyne__interpreter__tests__ordered_list_in_unordered.snap
new file mode 100644
index 00000000..26b81c98
--- /dev/null
+++ b/src/interpreter/snapshots/inlyne__interpreter__tests__ordered_list_in_unordered.snap
@@ -0,0 +1,72 @@
+---
+source: src/interpreter/tests.rs
+description: " --- md\n\n- bullet\n 1. 1st inner\n- bullet\n\n\n --- html\n\n\n- bullet\n
\n- 1st inner
\n
\n \n- bullet
\n
\n"
+expression: interpret_md(text)
+---
+[
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "· ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "bullet",
+ default_color: Color(BLACK),
+ ..
+ },
+ Text {
+ text: " ",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 100.0,
+ texts: [
+ Text {
+ text: "1. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "1st inner",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "· ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "bullet",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ Spacer(
+ InvisibleSpacer(5),
+ ),
+]
diff --git a/src/interpreter/snapshots/inlyne__interpreter__tests__unordered_list_in_ordered.snap b/src/interpreter/snapshots/inlyne__interpreter__tests__unordered_list_in_ordered.snap
new file mode 100644
index 00000000..fa68bd09
--- /dev/null
+++ b/src/interpreter/snapshots/inlyne__interpreter__tests__unordered_list_in_ordered.snap
@@ -0,0 +1,72 @@
+---
+source: src/interpreter/tests.rs
+description: " --- md\n\n1. 1st outer\n - bullet\n2. 2nd outer\n\n\n --- html\n\n\n- 1st outer\n\n
\n- 2nd outer
\n
\n"
+expression: interpret_md(text)
+---
+[
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "1. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "1st outer",
+ default_color: Color(BLACK),
+ ..
+ },
+ Text {
+ text: " ",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 100.0,
+ texts: [
+ Text {
+ text: "· ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "bullet",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ TextBox(
+ TextBox {
+ indent: 50.0,
+ texts: [
+ Text {
+ text: "2. ",
+ default_color: Color(BLACK),
+ style: BOLD ,
+ ..
+ },
+ Text {
+ text: "2nd outer",
+ default_color: Color(BLACK),
+ ..
+ },
+ ],
+ ..
+ },
+ ),
+ Spacer(
+ InvisibleSpacer(5),
+ ),
+]
diff --git a/src/interpreter/tests.rs b/src/interpreter/tests.rs
index 002f9360..ff9397f0 100644
--- a/src/interpreter/tests.rs
+++ b/src/interpreter/tests.rs
@@ -167,6 +167,24 @@ let v = 1;
```
";
+const UNORDERED_LIST_IN_ORDERED: &str = "\
+1. 1st outer
+ - bullet
+2. 2nd outer
+";
+
+const NESTED_ORDERED_LIST: &str = "\
+1. 1st outer
+ 1. 1st inner
+2. 2nd outer
+";
+
+const ORDERED_LIST_IN_UNORDERED: &str = "\
+- bullet
+ 1. 1st inner
+- bullet
+";
+
snapshot_interpreted_elements!(
(footnotes_list_prefix, FOOTNOTES_LIST_PREFIX),
(checklist_has_no_text_prefix, CHECKLIST_HAS_NO_TEXT_PREFIX),
@@ -174,6 +192,9 @@ snapshot_interpreted_elements!(
(bare_link_gets_autolinked, BARE_LINK_GETS_AUTOLINKED),
(toml_gets_highlighted, TOML_GETS_HIGHLIGHTED),
(handles_comma_in_info_str, HANDLES_COMMA_IN_INFO_STR),
+ (unordered_list_in_ordered, UNORDERED_LIST_IN_ORDERED),
+ (nested_ordered_list, NESTED_ORDERED_LIST),
+ (ordered_list_in_unordered, ORDERED_LIST_IN_UNORDERED),
);
/// Spin up a server, so we can test network requests without external services