use gformat

This commit is contained in:
yggverse 2024-09-27 01:16:54 +03:00
parent b408eaf4f2
commit fa95f7ffdd
4 changed files with 23 additions and 30 deletions

View file

@ -1,4 +1,4 @@
use gtk::glib::{markup_escape_text, GString, Regex, RegexCompileFlags, RegexMatchFlags};
use gtk::glib::{gformat, markup_escape_text, GString, Regex, RegexCompileFlags, RegexMatchFlags};
pub enum Level {
H1,
@ -42,18 +42,18 @@ impl Header {
// Init markup
let markup = match level {
Level::H1 => GString::from(format!(
Level::H1 => gformat!(
"<span size=\"xx-large\">{}</span>\n",
markup_escape_text(&text)
)),
Level::H2 => GString::from(format!(
),
Level::H2 => gformat!(
"<span size=\"x-large\">{}</span>\n",
markup_escape_text(&text)
)),
Level::H3 => GString::from(format!(
),
Level::H3 => gformat!(
"<span size=\"large\">{}</span>\n",
markup_escape_text(&text)
)),
),
_ => return None,
};

View file

@ -1,5 +1,5 @@
use gtk::glib::{
markup_escape_text, GString, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
gformat, markup_escape_text, GString, Regex, RegexCompileFlags, RegexMatchFlags, Uri, UriFlags,
};
pub struct Link {
@ -83,12 +83,12 @@ impl Link {
}
// Markup
markup = GString::from(format!(
markup = gformat!(
"<a href=\"{}\" title=\"{}\"><span underline=\"none\">{}</span></a>\n",
markup_escape_text(&uri.to_str()), // use resolved address for href
markup_escape_text(&link), // show original address for title
markup_escape_text(&name.join(" ")),
));
);
Some(Self {
alt,

View file

@ -1,23 +1,17 @@
use gtk::glib::{markup_escape_text, GString};
use gtk::glib::{gformat, 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),
markup: gformat!("{}\n", markup_escape_text(line)),
}
}
pub fn markup(&self) -> &GString {
&self.markup
}
pub fn source(&self) -> &GString {
&self.source
}
}