ggemtext/src/line/quote.rs
2024-12-03 19:42:13 +02:00

26 lines
641 B
Rust

use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// [Quote](https://geminiprotocol.net/docs/gemtext-specification.gmi#quote-lines) entity holder
pub struct Quote {
pub value: String,
}
impl Quote {
// Constructors
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(
r"^>\s*(.*)$",
line,
RegexCompileFlags::DEFAULT,
RegexMatchFlags::DEFAULT,
);
// Extract formatted value
Some(Self {
value: regex.get(1)?.trim().to_string(),
})
}
}