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 struct ListItem {
pub(crate) text: Inline, pub(crate) text: Inline,
pub(crate) level: u16, pub(crate) level: u16,
pub(crate) ordered: bool,
pub(crate) children: Vec<ListItem>, pub(crate) children: Vec<ListItem>,
} }
@ -213,10 +214,11 @@ impl List {
} }
impl ListItem { impl ListItem {
pub fn new(text: Inline, level: u16) -> Self { pub fn new(text: Inline, level: u16, ordered: bool) -> Self {
Self { Self {
text, text,
level, level,
ordered,
children: Vec::new(), children: Vec::new(),
} }
} }

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

@ -433,6 +433,7 @@ impl Parser {
if self.check_linebreak() || path.is_empty() { if self.check_linebreak() || path.is_empty() {
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
parse_option!(self.next_char(), self.index);
if let Ok(anchor) = self.import_document(path.clone()) { if let Ok(anchor) = self.import_document(path.clone()) {
Ok(Import { path, anchor }) Ok(Import { path, anchor })
@ -534,6 +535,7 @@ impl Parser {
if !self.check_special_group(&LIST_SPECIAL_CHARS) && !self.current_char.is_numeric() { if !self.check_special_group(&LIST_SPECIAL_CHARS) && !self.current_char.is_numeric() {
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
let ordered = self.current_char.is_numeric();
while let Some(character) = self.next_char() { while let Some(character) = self.next_char() {
if character.is_whitespace() { if character.is_whitespace() {
break; break;
@ -543,7 +545,7 @@ impl Parser {
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
self.seek_inline_whitespace(); 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) Ok(item)
} }
@ -778,7 +780,7 @@ impl Parser {
|| (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND)) || (count > 0 && self.check_special_group(&INLINE_SPECIAL_CHARS_SECOND))
{ {
break; break;
} else { } else if !self.check_special(&SPECIAL_ESCAPE) {
characters.push(current_char) characters.push(current_char)
} }
if let Some(character) = self.next_char() { if let Some(character) = self.next_char() {

Loading…
Cancel
Save