mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement plain line parser
This commit is contained in:
parent
9a130a7422
commit
f294d55cfe
3 changed files with 31 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
mod parser;
|
||||
|
||||
use parser::header::Header;
|
||||
use parser::plain::Plain;
|
||||
|
||||
use gtk::{
|
||||
prelude::{StyleContextExt, WidgetExt},
|
||||
|
|
@ -19,10 +20,16 @@ impl Reader {
|
|||
let mut markup = String::new();
|
||||
|
||||
for line in gemtext.lines() {
|
||||
// Is header
|
||||
if let Some(header) = Header::from(line) {
|
||||
markup.push_str(header.markup());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is link @TODO
|
||||
|
||||
// Nothing match, escape string just
|
||||
markup.push_str(Plain::from(line).markup())
|
||||
}
|
||||
|
||||
// Init CSS
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
pub mod header;
|
||||
pub mod plain;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
use gtk::glib::{markup_escape_text, GString};
|
||||
|
||||
pub struct Plain {
|
||||
markup: GString,
|
||||
source: GString,
|
||||
}
|
||||
|
||||
impl Plain {
|
||||
pub fn from(line: &str) -> Plain {
|
||||
Self {
|
||||
markup: GString::from(format!("{}\n", markup_escape_text(line))),
|
||||
source: GString::from(line),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn markup(&self) -> &GString {
|
||||
&self.markup
|
||||
}
|
||||
|
||||
pub fn source(&self) -> &GString {
|
||||
&self.source
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue