mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
init text/markdown parser (based on text/gemini)
This commit is contained in:
parent
6fb7e70213
commit
fc6cce8072
23 changed files with 1452 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
mod gemini;
|
||||
mod markdown;
|
||||
mod nex;
|
||||
mod plain;
|
||||
mod source;
|
||||
|
|
@ -7,6 +8,7 @@ use super::{ItemAction, WindowAction};
|
|||
use adw::ClampScrollable;
|
||||
use gemini::Gemini;
|
||||
use gtk::{ScrolledWindow, TextView, glib::Uri};
|
||||
use markdown::Markdown;
|
||||
use nex::Nex;
|
||||
use plain::Plain;
|
||||
use source::Source;
|
||||
|
|
@ -51,6 +53,34 @@ impl Text {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn markdown(
|
||||
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,
|
||||
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,
|
||||
},
|
||||
}),
|
||||
)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plain(data: &str) -> Self {
|
||||
let text_view = TextView::plain(data);
|
||||
Self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue