From 822c3e3b66f1ded9d8a8c3880fd4e5dd90d546ec Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Mon, 26 Aug 2024 20:50:23 +0200 Subject: [PATCH] Better lists offset --- src/elements/list.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/elements/list.rs b/src/elements/list.rs index f91939b..92b71c1 100644 --- a/src/elements/list.rs +++ b/src/elements/list.rs @@ -79,7 +79,16 @@ impl Element for ListEntry { fn compile(&self, compiler: &Compiler, document: &dyn Document, cursor: usize) -> Result { match compiler.target() { Target::HTML => { - let mut result = "
  • ".to_string(); + let mut result = String::new(); + if let Some((numbered, number)) = self.numbering.last() + { + if *numbered { + result += format!("
  • ").as_str(); + } + else { + result += "
  • "; + } + } for elem in &self.content { result += elem.compile(compiler, document, cursor+result.len())?.as_str(); } @@ -198,14 +207,13 @@ impl ListRule { fn parse_depth(depth: &str, document: &dyn Document, offset: usize) -> Vec<(bool, usize)> { let mut parsed = vec![]; - // FIXME: Previous iteration used to recursively retrieve the list indent let prev_entry = document .last_element::() .and_then(|entry| Ref::filter_map(entry, |e| Some(&e.numbering)).ok()); let mut continue_match = true; depth.chars().enumerate().for_each(|(idx, c)| { - let number = if offset == 0 { + let number = if offset == usize::MAX { prev_entry .as_ref() .and_then(|v| { @@ -312,7 +320,7 @@ impl Rule for ListRule { let depth = ListRule::parse_depth( captures.get(1).unwrap().as_str(), document, - offset.unwrap_or(0), + offset.unwrap_or(usize::MAX), ); // Content