diff --git a/src/elements.rs b/src/elements.rs index aa83865..c90bf9c 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -48,6 +48,7 @@ pub struct List { pub struct ListItem { pub(crate) text: Inline, pub(crate) level: u16, + pub(crate) ordered: bool, pub(crate) children: Vec, } @@ -213,10 +214,11 @@ impl List { } impl ListItem { - pub fn new(text: Inline, level: u16) -> Self { + pub fn new(text: Inline, level: u16, ordered: bool) -> Self { Self { text, level, + ordered, children: Vec::new(), } } diff --git a/src/format/html.rs b/src/format/html.rs index 06ce14d..a74b98b 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -84,7 +84,7 @@ impl ToHtml for Paragraph { let inner = self .elements .iter() - .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())); + .fold("".to_string(), |a, b| format!("{}
{}", a, b.to_html())); format!("

{}

", inner) } } @@ -109,7 +109,15 @@ impl ToHtml for ListItem { .children .iter() .fold("".to_string(), |a, b| format!("{}{}", a, b.to_html())); - format!("
  • {}
  • ", self.text.to_html(), inner) + if let Some(first) = self.children.first() { + if first.ordered { + format!("
  • {}
      {}
  • ", self.text.to_html(), inner) + } else { + format!("
  • {}
  • ", self.text.to_html(), inner) + } + } else { + format!("
  • {}
  • ", self.text.to_html()) + } } } @@ -145,7 +153,7 @@ impl ToHtml for Cell { impl ToHtml for CodeBlock { fn to_html(&self) -> String { format!( - "
    {}
    ", + "
    {}
    ", self.language.clone(), self.code.clone() ) diff --git a/src/parser.rs b/src/parser.rs index 23960c7..4f5645f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -433,6 +433,7 @@ impl Parser { if self.check_linebreak() || path.is_empty() { return Err(self.revert_with_error(start_index)); } + parse_option!(self.next_char(), self.index); if let Ok(anchor) = self.import_document(path.clone()) { Ok(Import { path, anchor }) @@ -534,6 +535,7 @@ impl Parser { if !self.check_special_group(&LIST_SPECIAL_CHARS) && !self.current_char.is_numeric() { return Err(self.revert_with_error(start_index)); } + let ordered = self.current_char.is_numeric(); while let Some(character) = self.next_char() { if character.is_whitespace() { break; @@ -543,7 +545,7 @@ impl Parser { return Err(self.revert_with_error(start_index)); } self.seek_inline_whitespace(); - let item = ListItem::new(self.parse_inline()?, level as u16); + let item = ListItem::new(self.parse_inline()?, level as u16, ordered); Ok(item) } @@ -778,7 +780,7 @@ impl Parser { || (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND)) { break; - } else { + } else if !self.check_special(&SPECIAL_ESCAPE) { characters.push(current_char) } if let Some(character) = self.next_char() {