Add Oblique token

This commit is contained in:
Juno Takano 2026-01-01 03:11:27 -03:00
commit 8ee0ad7977
3 changed files with 70 additions and 1 deletions

View file

@ -8,6 +8,7 @@ pub mod span;
pub mod header;
pub mod preformat;
pub mod code;
pub mod oblique;
#[derive(Debug, Eq, PartialEq)]
pub enum Token {
@ -16,6 +17,7 @@ pub enum Token {
Header(header::Header),
LineBreak(linebreak::LineBreak),
Literal(literal::Literal),
Oblique(oblique::Oblique),
Paragraph(paragraph::Paragraph),
PreFormat(preformat::PreFormat),
Span(span::Span),
@ -29,6 +31,7 @@ impl Token {
Token::Header(ref d) => d.render(),
Token::LineBreak(ref d) => d.render(),
Token::Literal(ref d) => d.render(),
Token::Oblique(ref d) => d.render(),
Token::Paragraph(ref d) => d.render(),
Token::PreFormat(ref d) => d.render(),
Token::Span(ref d) => d.render(),

View file

@ -0,0 +1,54 @@
use crate::{
syntax::content::{Parseable, Lexeme},
};
#[derive(Debug, Eq, PartialEq)]
pub struct Oblique {
open: bool,
}
impl Oblique {
pub fn new(open: bool) -> Oblique {
Oblique { open }
}
}
impl Parseable for Oblique {
fn probe(lexeme: &Lexeme) -> bool {
lexeme.text() == "_"
}
fn lex(_lexeme: &Lexeme) -> Oblique {
panic!("Attempt to lex an oblique tag directly from a lexeme")
}
fn render(&self) -> String {
if self.open {
String::from("<em>")
} else {
String::from("</em>")
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn render() {
let code_open = Oblique::new(true);
assert_eq!(code_open.render(), "<em>");
let code_closed = Oblique::new(false);
assert_eq!(code_closed.render(), "</em>");
}
#[test]
#[should_panic(
expected = "Attempt to lex an oblique tag directly from a lexeme"
)]
fn lex() {
Oblique::lex(&Lexeme::new("", ""));
}
}