Implement verse token, scaffold quote token
This commit is contained in:
parent
3ea6c53920
commit
aa41e33ced
9 changed files with 325 additions and 45 deletions
|
|
@ -7,7 +7,7 @@ pub struct LineBreak {}
|
|||
|
||||
impl Parseable for LineBreak {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
lexeme.text() == "\n" && !lexeme.last()
|
||||
lexeme.match_char('<') && lexeme.match_next_char('\n')
|
||||
}
|
||||
|
||||
fn lex(_lexeme: &Lexeme) -> LineBreak {
|
||||
|
|
@ -15,7 +15,7 @@ impl Parseable for LineBreak {
|
|||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
"\n".to_owned()
|
||||
String::from("<br>")
|
||||
}
|
||||
|
||||
fn flatten(&self) -> String {
|
||||
|
|
|
|||
58
src/syntax/content/parser/token/quote.rs
Normal file
58
src/syntax/content/parser/token/quote.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
use crate::syntax::content::{Parseable, parser::Lexeme};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Quote {
|
||||
open: Option<bool>,
|
||||
}
|
||||
|
||||
impl Quote {
|
||||
pub fn new(open: bool) -> Quote {
|
||||
Quote { open: Some(open) }
|
||||
}
|
||||
|
||||
pub fn probe_end(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_char_sequence('\n', '\n')
|
||||
}
|
||||
}
|
||||
|
||||
impl Parseable for Quote {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_char('>') && lexeme.match_next_char(' ')
|
||||
}
|
||||
|
||||
fn lex(_lexeme: &Lexeme) -> Quote {
|
||||
Quote { open: None }
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
if let Some(open) = self.open {
|
||||
if open {
|
||||
"<blockquote>".to_owned()
|
||||
} else {
|
||||
"</blockquote>".to_owned()
|
||||
}
|
||||
} else {
|
||||
panic!("Attempt to render a quote tag while open state is unknown")
|
||||
}
|
||||
}
|
||||
|
||||
fn flatten(&self) -> String {
|
||||
String::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Quote {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let display_open_state = match self.open {
|
||||
Some(open_state) => {
|
||||
if open_state {
|
||||
"open"
|
||||
} else {
|
||||
"closed"
|
||||
}
|
||||
},
|
||||
None => "unknown",
|
||||
};
|
||||
write!(f, "Quote [{display_open_state}]")
|
||||
}
|
||||
}
|
||||
72
src/syntax/content/parser/token/verse.rs
Normal file
72
src/syntax/content/parser/token/verse.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
use crate::syntax::content::{Parseable, parser::Lexeme};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct Verse {
|
||||
open: Option<bool>,
|
||||
citation: Option<String>,
|
||||
}
|
||||
|
||||
impl Verse {
|
||||
pub fn new(open: bool) -> Verse {
|
||||
Verse {
|
||||
open: Some(open),
|
||||
citation: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn probe_end(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_char_triple('\n', '&', '\n')
|
||||
}
|
||||
}
|
||||
|
||||
impl Parseable for Verse {
|
||||
fn probe(lexeme: &Lexeme) -> bool {
|
||||
lexeme.match_char_triple('\n', '&', '\n')
|
||||
}
|
||||
|
||||
fn lex(_lexeme: &Lexeme) -> Verse {
|
||||
Verse {
|
||||
open: None,
|
||||
citation: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn render(&self) -> String {
|
||||
if let Some(open) = self.open {
|
||||
if open {
|
||||
concat!("\n", r#"<p class="verse">"#).to_string()
|
||||
} else {
|
||||
"\n</p>\n".to_owned()
|
||||
}
|
||||
} else {
|
||||
panic!("Attempt to render a verse tag while open state is unknown")
|
||||
}
|
||||
}
|
||||
|
||||
fn flatten(&self) -> String {
|
||||
String::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Verse {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let display_open_state = match self.open {
|
||||
Some(open_state) => {
|
||||
if open_state {
|
||||
"open"
|
||||
} else {
|
||||
"closed"
|
||||
}
|
||||
},
|
||||
None => "unknown",
|
||||
};
|
||||
|
||||
let citation = if self.citation.is_some() {
|
||||
" cited"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
write!(f, "Verse [{display_open_state}{citation}]")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue