Add ruler defined with - - -

pull/1/head
trivernis 5 years ago
parent 4090ce6814
commit 22b6c9cc00

@ -14,6 +14,7 @@ pub enum Block {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Inline { pub enum Inline {
Text(Text), Text(Text),
Ruler(Ruler),
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -101,6 +102,9 @@ pub struct InlineMetadata {
pub(crate) data: String, pub(crate) data: String,
} }
#[derive(Clone, Debug)]
pub struct Ruler {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Text { pub struct Text {
pub subtext: Vec<SubText>, pub subtext: Vec<SubText>,

@ -8,6 +8,7 @@ impl ToHtml for Inline {
fn to_html(&self) -> String { fn to_html(&self) -> String {
match self { match self {
Inline::Text(text) => text.to_html(), 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 {
"<hr>".to_string()
}
}
impl ToHtml for Text { impl ToHtml for Text {
fn to_html(&self) -> String { fn to_html(&self) -> String {
self.subtext self.subtext

@ -559,7 +559,7 @@ impl Parser {
break; break;
} }
} }
if self.next_char() == None { if self.next_char() == None || self.check_special(&MINUS) {
return Err(self.revert_with_error(start_index)); return Err(self.revert_with_error(start_index));
} }
self.seek_inline_whitespace(); self.seek_inline_whitespace();
@ -631,7 +631,29 @@ impl Parser {
if self.index > self.text.len() { if self.index > self.text.len() {
Err(ParseError::new(self.index)) Err(ParseError::new(self.index))
} else { } 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<Ruler, ParseError> {
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))
} }
} }

@ -19,6 +19,7 @@ pub(crate) const X: char = 'x';
pub(crate) const GT: char = '>'; pub(crate) const GT: char = '>';
pub(crate) const LT: char = '<'; pub(crate) const LT: char = '<';
pub(crate) const BANG: char = '!'; pub(crate) const BANG: char = '!';
pub(crate) const SPACE: char = ' ';
// aliases // aliases
@ -46,6 +47,7 @@ pub(crate) const BLOCK_SPECIAL_CHARS: [char; 7] = [
META_OPEN, META_OPEN,
IMPORT_START, IMPORT_START,
]; ];
pub(crate) const INLINE_SPECIAL_CHARS: [char; 6] = [LB, ASTERISK, UNDERSCR, TILDE, PIPE, BACKTICK]; 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]; 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 // sequences
pub(crate) const SQ_CODE_BLOCK: [char; 3] = [BACKTICK, BACKTICK, BACKTICK]; pub(crate) const SQ_CODE_BLOCK: [char; 3] = [BACKTICK, BACKTICK, BACKTICK];
pub(crate) const SQ_RULER: [char; 5] = [MINUS, SPACE, MINUS, SPACE, MINUS];
// expressions // expressions

Loading…
Cancel
Save