mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
implement plain line parser
This commit is contained in:
parent
9a130a7422
commit
f294d55cfe
@ -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
|
||||||
|
@ -1 +1,2 @@
|
|||||||
pub mod header;
|
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…
x
Reference in New Issue
Block a user