implement plain line parser

This commit is contained in:
yggverse 2024-09-26 20:58:31 +03:00
parent 9a130a7422
commit f294d55cfe
3 changed files with 31 additions and 0 deletions

View File

@ -1,6 +1,7 @@
mod parser; mod parser;
use parser::header::Header; use parser::header::Header;
use parser::plain::Plain;
use gtk::{ use gtk::{
prelude::{StyleContextExt, WidgetExt}, prelude::{StyleContextExt, WidgetExt},
@ -19,10 +20,16 @@ impl Reader {
let mut markup = String::new(); let mut markup = String::new();
for line in gemtext.lines() { for line in gemtext.lines() {
// Is header
if let Some(header) = Header::from(line) { if let Some(header) = Header::from(line) {
markup.push_str(header.markup()); markup.push_str(header.markup());
continue; continue;
} }
// Is link @TODO
// Nothing match, escape string just
markup.push_str(Plain::from(line).markup())
} }
// Init CSS // Init CSS

View File

@ -1 +1,2 @@
pub mod header; pub mod header;
pub mod plain;

View File

@ -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
}
}