mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
update ggemtext api, use const for shared values
This commit is contained in:
parent
cdf6e78408
commit
1224353feb
@ -27,6 +27,9 @@ use gtk::{
|
|||||||
};
|
};
|
||||||
use std::{collections::HashMap, rc::Rc};
|
use std::{collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
|
pub const DATE_FORMAT: &str = "%Y-%m-%d";
|
||||||
|
pub const NEW_LINE: &str = "\n";
|
||||||
|
|
||||||
pub struct Reader {
|
pub struct Reader {
|
||||||
pub title: Option<GString>,
|
pub title: Option<GString>,
|
||||||
pub widget: Rc<Widget>,
|
pub widget: Rc<Widget>,
|
||||||
@ -64,7 +67,7 @@ impl Reader {
|
|||||||
code.value.as_str(),
|
code.value.as_str(),
|
||||||
&[&tag.code.text_tag],
|
&[&tag.code.text_tag],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Skip other actions for this line
|
// Skip other actions for this line
|
||||||
continue;
|
continue;
|
||||||
@ -95,17 +98,17 @@ impl Reader {
|
|||||||
alt.as_str(),
|
alt.as_str(),
|
||||||
&[&tag.title.text_tag],
|
&[&tag.title.text_tag],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert multiline code buffer into main buffer
|
// Insert multiline code buffer into main buffer
|
||||||
buffer.insert_with_tags(
|
buffer.insert_with_tags(
|
||||||
&mut buffer.end_iter(),
|
&mut buffer.end_iter(),
|
||||||
&this.buffer.join("\n"),
|
&this.value,
|
||||||
&[&tag.code.text_tag],
|
&[&tag.code.text_tag],
|
||||||
);
|
);
|
||||||
|
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Reset
|
// Reset
|
||||||
multiline = None;
|
multiline = None;
|
||||||
@ -131,7 +134,7 @@ impl Reader {
|
|||||||
Level::H3 => &tag.h3.text_tag,
|
Level::H3 => &tag.h3.text_tag,
|
||||||
}],
|
}],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Update reader title using first gemtext header match
|
// Update reader title using first gemtext header match
|
||||||
if title.is_none() {
|
if title.is_none() {
|
||||||
@ -157,7 +160,7 @@ impl Reader {
|
|||||||
// Append date on exist
|
// Append date on exist
|
||||||
if let Some(timestamp) = link.timestamp {
|
if let Some(timestamp) = link.timestamp {
|
||||||
// https://docs.gtk.org/glib/method.DateTime.format.html
|
// https://docs.gtk.org/glib/method.DateTime.format.html
|
||||||
if let Ok(value) = timestamp.format("%Y-%m-%d") {
|
if let Ok(value) = timestamp.format(DATE_FORMAT) {
|
||||||
alt.push(value.to_string())
|
alt.push(value.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +184,7 @@ impl Reader {
|
|||||||
|
|
||||||
// Append alt vector values to buffer
|
// Append alt vector values to buffer
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
|
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Append tag to HashMap storage
|
// Append tag to HashMap storage
|
||||||
links.insert(a, link.uri.clone());
|
links.insert(a, link.uri.clone());
|
||||||
@ -198,7 +201,7 @@ impl Reader {
|
|||||||
format!("• {}", list.value).as_str(),
|
format!("• {}", list.value).as_str(),
|
||||||
&[&tag.list.text_tag],
|
&[&tag.list.text_tag],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Skip other actions for this line
|
// Skip other actions for this line
|
||||||
continue;
|
continue;
|
||||||
@ -212,7 +215,7 @@ impl Reader {
|
|||||||
quote.value.as_str(),
|
quote.value.as_str(),
|
||||||
&[&tag.quote.text_tag],
|
&[&tag.quote.text_tag],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Skip other actions for this line
|
// Skip other actions for this line
|
||||||
continue;
|
continue;
|
||||||
@ -224,7 +227,7 @@ impl Reader {
|
|||||||
|
|
||||||
buffer.tag_table().add(&tag);
|
buffer.tag_table().add(&tag);
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]);
|
buffer.insert_with_tags(&mut buffer.end_iter(), line, &[&tag]);
|
||||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init additional controllers
|
// Init additional controllers
|
||||||
|
Loading…
x
Reference in New Issue
Block a user