Add ordering to sublists and fix escape

pull/1/head
trivernis 5 years ago
parent bc1d620aa0
commit 6db67c9139

@ -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<ListItem>,
}
@ -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(),
}
}

@ -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!("{}<br>{}", a, b.to_html()));
format!("<p>{}</p>", inner)
}
}
@ -109,8 +109,16 @@ impl ToHtml for ListItem {
.children
.iter()
.fold("".to_string(), |a, b| format!("{}{}", a, b.to_html()));
if let Some(first) = self.children.first() {
if first.ordered {
format!("<li>{}<ol>{}</ol></li>", self.text.to_html(), inner)
} else {
format!("<li>{}<ul>{}</ul></li>", self.text.to_html(), inner)
}
} else {
format!("<li>{}</li>", self.text.to_html())
}
}
}
impl ToHtml for Table {
@ -145,7 +153,7 @@ impl ToHtml for Cell {
impl ToHtml for CodeBlock {
fn to_html(&self) -> String {
format!(
"<div><code lang='{}'>{}</code></div>",
"<div><code lang='{}'><pre>{}</pre></code></div>",
self.language.clone(),
self.code.clone()
)

@ -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() {

Loading…
Cancel
Save