diff --git a/src/elements.rs b/src/elements.rs index c90bf9c..ca5856c 100644 --- a/src/elements.rs +++ b/src/elements.rs @@ -14,6 +14,7 @@ pub enum Block { #[derive(Clone, Debug)] pub enum Inline { Text(Text), + Ruler(Ruler), } #[derive(Clone, Debug)] @@ -101,6 +102,9 @@ pub struct InlineMetadata { pub(crate) data: String, } +#[derive(Clone, Debug)] +pub struct Ruler {} + #[derive(Clone, Debug)] pub struct Text { pub subtext: Vec, diff --git a/src/format/html.rs b/src/format/html.rs index a74b98b..1a14785 100644 --- a/src/format/html.rs +++ b/src/format/html.rs @@ -8,6 +8,7 @@ impl ToHtml for Inline { fn to_html(&self) -> String { match self { Inline::Text(text) => text.to_html(), + Inline::Ruler(ruler) => ruler.to_html(), } } } @@ -177,6 +178,12 @@ impl ToHtml for Quote { } } +impl ToHtml for Ruler { + fn to_html(&self) -> String { + "
".to_string() + } +} + impl ToHtml for Text { fn to_html(&self) -> String { self.subtext diff --git a/src/parser.rs b/src/parser.rs index 6c29f20..98e0a2d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -559,7 +559,7 @@ impl Parser { break; } } - if self.next_char() == None { + if self.next_char() == None || self.check_special(&MINUS) { return Err(self.revert_with_error(start_index)); } self.seek_inline_whitespace(); @@ -631,7 +631,29 @@ impl Parser { if self.index > self.text.len() { Err(ParseError::new(self.index)) } else { - Ok(Inline::Text(self.parse_text()?)) + if let Ok(ruler) = self.parse_ruler() { + return Ok(Inline::Ruler(ruler)); + } else if let Ok(text) = self.parse_text() { + return Ok(Inline::Text(text)); + } + return Err(ParseError::new(self.index)); + } + } + + /// parses a ruler + fn parse_ruler(&mut self) -> Result { + let start_index = self.index; + self.seek_inline_whitespace(); + if let Ok(_) = self.check_special_sequence(&SQ_RULER) { + while let Some(character) = self.next_char() { + // seek until end of line + if character == LB { + break; + } + } + Ok(Ruler {}) + } else { + Err(self.revert_with_error(start_index)) } } diff --git a/src/tokens.rs b/src/tokens.rs index e40f89a..a631734 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -19,6 +19,7 @@ pub(crate) const X: char = 'x'; pub(crate) const GT: char = '>'; pub(crate) const LT: char = '<'; pub(crate) const BANG: char = '!'; +pub(crate) const SPACE: char = ' '; // aliases @@ -46,6 +47,7 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [char; 7] = [ META_OPEN, IMPORT_START, ]; + pub(crate) const INLINE_SPECIAL_CHARS: [char; 6] = [LB, ASTERISK, UNDERSCR, TILDE, PIPE, BACKTICK]; pub(crate) const INLINE_SPECIAL_CHARS_SECOND: [char; 3] = [DESC_OPEN, IMG_START, URL_OPEN]; @@ -54,6 +56,7 @@ pub(crate) const LIST_SPECIAL_CHARS: [char; 4] = [MINUS, PLUS, ASTERISK, O]; // sequences pub(crate) const SQ_CODE_BLOCK: [char; 3] = [BACKTICK, BACKTICK, BACKTICK]; +pub(crate) const SQ_RULER: [char; 5] = [MINUS, SPACE, MINUS, SPACE, MINUS]; // expressions