mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +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`
|
||||
pub fn to_text_markdown(&self, base: &Uri, data: &str) -> Text {
|
||||
self.clean();
|
||||
match Text::markdown((&self.window_action, &self.item_action), base, data) {
|
||||
Ok(text) => {
|
||||
self.g_box.append(&text.scrolled_window);
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
let m = Text::markdown((&self.window_action, &self.item_action), base, data);
|
||||
self.g_box.append(&m.scrolled_window);
|
||||
m
|
||||
}
|
||||
|
||||
/// `text/plain`
|
||||
|
|
|
|||
|
|
@ -57,26 +57,13 @@ impl Text {
|
|||
actions: (&Rc<WindowAction>, &Rc<ItemAction>),
|
||||
base: &Uri,
|
||||
gemtext: &str,
|
||||
) -> Result<Self, (String, Option<Self>)> {
|
||||
match Markdown::build(actions, base, gemtext) {
|
||||
Ok(widget) => Ok(Self {
|
||||
scrolled_window: reader(&widget.text_view),
|
||||
text_view: widget.text_view,
|
||||
) -> Self {
|
||||
let markdown = Markdown::build(actions, base, gemtext);
|
||||
Self {
|
||||
scrolled_window: reader(&markdown.text_view),
|
||||
text_view: markdown.text_view,
|
||||
meta: Meta {
|
||||
title: widget.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,
|
||||
},
|
||||
}),
|
||||
)),
|
||||
title: markdown.title,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ impl Markdown {
|
|||
(window_action, item_action): (&Rc<WindowAction>, &Rc<ItemAction>),
|
||||
base: &Uri,
|
||||
markdown: &str,
|
||||
) -> Result<Self, Error> {
|
||||
) -> Self {
|
||||
// Init HashMap storage (for event controllers)
|
||||
let mut links: HashMap<TextTag, Uri> = HashMap::new();
|
||||
|
||||
|
|
@ -81,22 +81,7 @@ impl Markdown {
|
|||
// Init gutter widget (the tooltip on URL tags hover)
|
||||
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
|
||||
// * keep in order!
|
||||
|
||||
let title = tags.render(&buffer, &base, &link_color.0, &mut links);
|
||||
|
||||
// Parse single-line markdown tags
|
||||
|
|
@ -418,15 +403,7 @@ impl Markdown {
|
|||
}
|
||||
}); // @TODO may be expensive for CPU, add timeout?
|
||||
|
||||
// Result
|
||||
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 },
|
||||
))
|
||||
}
|
||||
Self { text_view, title }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue