mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 08:35:28 +00:00
remove extras
This commit is contained in:
parent
1706f14e96
commit
d674edc7d0
3 changed files with 12 additions and 69 deletions
|
|
@ -157,30 +157,9 @@ impl Content {
|
||||||
/// `text/markdown`
|
/// `text/markdown`
|
||||||
pub fn to_text_markdown(&self, base: &Uri, data: &str) -> Text {
|
pub fn to_text_markdown(&self, base: &Uri, data: &str) -> Text {
|
||||||
self.clean();
|
self.clean();
|
||||||
match Text::markdown((&self.window_action, &self.item_action), base, data) {
|
let m = Text::markdown((&self.window_action, &self.item_action), base, data);
|
||||||
Ok(text) => {
|
self.g_box.append(&m.scrolled_window);
|
||||||
self.g_box.append(&text.scrolled_window);
|
m
|
||||||
text
|
|
||||||
}
|
|
||||||
Err((message, text)) => {
|
|
||||||
self.g_box.append(&{
|
|
||||||
let banner = adw::Banner::builder()
|
|
||||||
.title(message)
|
|
||||||
.revealed(true)
|
|
||||||
.button_label("Ok")
|
|
||||||
.build();
|
|
||||||
banner.connect_button_clicked(|this| this.set_revealed(false));
|
|
||||||
banner
|
|
||||||
});
|
|
||||||
match text {
|
|
||||||
Some(text) => {
|
|
||||||
self.g_box.append(&text.scrolled_window);
|
|
||||||
text
|
|
||||||
}
|
|
||||||
None => todo!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `text/plain`
|
/// `text/plain`
|
||||||
|
|
|
||||||
|
|
@ -57,26 +57,13 @@ impl Text {
|
||||||
actions: (&Rc<WindowAction>, &Rc<ItemAction>),
|
actions: (&Rc<WindowAction>, &Rc<ItemAction>),
|
||||||
base: &Uri,
|
base: &Uri,
|
||||||
gemtext: &str,
|
gemtext: &str,
|
||||||
) -> Result<Self, (String, Option<Self>)> {
|
) -> Self {
|
||||||
match Markdown::build(actions, base, gemtext) {
|
let markdown = Markdown::build(actions, base, gemtext);
|
||||||
Ok(widget) => Ok(Self {
|
Self {
|
||||||
scrolled_window: reader(&widget.text_view),
|
scrolled_window: reader(&markdown.text_view),
|
||||||
text_view: widget.text_view,
|
text_view: markdown.text_view,
|
||||||
meta: Meta {
|
meta: Meta {
|
||||||
title: widget.title,
|
title: markdown.title,
|
||||||
},
|
|
||||||
}),
|
|
||||||
Err(e) => match e {
|
|
||||||
markdown::Error::Markup(message, widget) => Err((
|
|
||||||
message,
|
|
||||||
Some(Self {
|
|
||||||
scrolled_window: reader(&widget.text_view),
|
|
||||||
text_view: widget.text_view,
|
|
||||||
meta: Meta {
|
|
||||||
title: widget.title,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ impl Markdown {
|
||||||
(window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>),
|
(window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>),
|
||||||
base: &Uri,
|
base: &Uri,
|
||||||
markdown: &str,
|
markdown: &str,
|
||||||
) -> Result<Self, Error> {
|
) -> Self {
|
||||||
// Init HashMap storage (for event controllers)
|
// Init HashMap storage (for event controllers)
|
||||||
let mut links: HashMap<TextTag, Uri> = HashMap::new();
|
let mut links: HashMap<TextTag, Uri> = HashMap::new();
|
||||||
|
|
||||||
|
|
@ -81,22 +81,7 @@ impl Markdown {
|
||||||
// Init gutter widget (the tooltip on URL tags hover)
|
// Init gutter widget (the tooltip on URL tags hover)
|
||||||
let gutter = Gutter::build(&text_view);
|
let gutter = Gutter::build(&text_view);
|
||||||
|
|
||||||
// Disable code format on at least one closing tag not found
|
|
||||||
// gemini://bbs.geminispace.org/s/Gemini/26031
|
|
||||||
let is_code_enabled = {
|
|
||||||
use ggemtext::line::code::{self};
|
|
||||||
let mut t: usize = 0;
|
|
||||||
for l in markdown.lines() {
|
|
||||||
if l.starts_with(code::TAG) {
|
|
||||||
t += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t == 0 || t.is_multiple_of(2)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Render markdown tags
|
// Render markdown tags
|
||||||
// * keep in order!
|
|
||||||
|
|
||||||
let title = tags.render(&buffer, &base, &link_color.0, &mut links);
|
let title = tags.render(&buffer, &base, &link_color.0, &mut links);
|
||||||
|
|
||||||
// Parse single-line markdown tags
|
// Parse single-line markdown tags
|
||||||
|
|
@ -418,15 +403,7 @@ impl Markdown {
|
||||||
}
|
}
|
||||||
}); // @TODO may be expensive for CPU, add timeout?
|
}); // @TODO may be expensive for CPU, add timeout?
|
||||||
|
|
||||||
// Result
|
Self { text_view, title }
|
||||||
if is_code_enabled {
|
|
||||||
Ok(Self { text_view, title })
|
|
||||||
} else {
|
|
||||||
Err(Error::Markup(
|
|
||||||
"Invalid multiline markup! Markdown format partially ignored.".to_string(),
|
|
||||||
Self { text_view, title },
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue