diff --git a/markdown-reader/TEST.md b/markdown-reader/TEST.md index 52f26bc..561159c 100644 --- a/markdown-reader/TEST.md +++ b/markdown-reader/TEST.md @@ -27,7 +27,7 @@ This is a ~~complicated~~ *very simple* example. ### Unordered - Item 1 -- Item 2 (currently buggy) +- Item 2 - Item 2a - Item 2b diff --git a/tui-markdown/src/lib.rs b/tui-markdown/src/lib.rs index d0c77b3..41f8c84 100644 --- a/tui-markdown/src/lib.rs +++ b/tui-markdown/src/lib.rs @@ -40,7 +40,7 @@ struct TextWriter<'a, I> { style: Style, /// Current list index as a stack of indices. - list_index: Vec, + list_index: Vec>, } impl<'a, I> TextWriter<'a, I> @@ -94,16 +94,22 @@ where Tag::CodeBlock(kind) => self.start_codeblock(kind), Tag::HtmlBlock => todo!(), Tag::List(start_index) => { - // TODO handle unordered lists properly (start_index is None for unordered lists) - self.start_list(start_index.unwrap_or(0)); + if let Some(line) = self.line.take() { + self.text.lines.push(line); + } + self.start_list(start_index); } Tag::Item => { let width = self.list_index.len() * 4 - 3; if let Some(index) = self.list_index.last_mut() { - let span = - Span::styled(format!("{:width$}. ", index), Style::new().light_blue()); + let span = match index { + None => Span::from(" ".repeat(width - 1) + "- "), + Some(index) => { + *index += 1; + format!("{:width$}. ", *index - 1).light_blue() + } + }; self.line = Some(span.into()); - *index += 1; } } Tag::FootnoteDefinition(_) => todo!(), @@ -225,7 +231,7 @@ where } } - fn start_list(&mut self, index: u64) { + fn start_list(&mut self, index: Option) { self.list_index.push(index); }