mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
detect reader title on first header tag match
This commit is contained in:
parent
f294d55cfe
commit
454feaeba5
@ -4,11 +4,13 @@ use parser::header::Header;
|
|||||||
use parser::plain::Plain;
|
use parser::plain::Plain;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
|
glib::GString,
|
||||||
prelude::{StyleContextExt, WidgetExt},
|
prelude::{StyleContextExt, WidgetExt},
|
||||||
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Reader {
|
pub struct Reader {
|
||||||
|
title: Option<GString>,
|
||||||
css: CssProvider,
|
css: CssProvider,
|
||||||
widget: Label,
|
widget: Label,
|
||||||
}
|
}
|
||||||
@ -16,13 +18,23 @@ pub struct Reader {
|
|||||||
impl Reader {
|
impl Reader {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(gemtext: &str) -> Self {
|
pub fn new(gemtext: &str) -> Self {
|
||||||
|
// Init title
|
||||||
|
let mut title = None;
|
||||||
|
|
||||||
// Init markup
|
// Init markup
|
||||||
let mut markup = String::new();
|
let mut markup = String::new();
|
||||||
|
|
||||||
for line in gemtext.lines() {
|
for line in gemtext.lines() {
|
||||||
// Is header
|
// Is header
|
||||||
if let Some(header) = Header::from(line) {
|
if let Some(header) = Header::from(line) {
|
||||||
|
// Format
|
||||||
markup.push_str(header.markup());
|
markup.push_str(header.markup());
|
||||||
|
|
||||||
|
// Set title from first document header tag
|
||||||
|
if title == None {
|
||||||
|
title = Some(header.text().clone());
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,10 +70,14 @@ impl Reader {
|
|||||||
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
Self { css, widget }
|
Self { title, css, widget }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
pub fn title(&self) -> &Option<GString> {
|
||||||
|
&self.title
|
||||||
|
}
|
||||||
|
|
||||||
pub fn widget(&self) -> &Label {
|
pub fn widget(&self) -> &Label {
|
||||||
&self.widget
|
&self.widget
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user