mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 01:00:02 +00:00
update ggemtext api to v0.3.0
This commit is contained in:
parent
2a59bebea9
commit
cdf6e78408
@ -21,7 +21,7 @@ version = "0.11.0"
|
||||
|
||||
[dependencies.gemtext]
|
||||
package = "ggemtext"
|
||||
version = "0.2.1"
|
||||
version = "0.3.0"
|
||||
|
||||
[dependencies.gtk]
|
||||
package = "gtk4"
|
||||
@ -35,6 +35,7 @@ version = "0.32.1"
|
||||
[dependencies.openssl]
|
||||
version = "0.10.68"
|
||||
|
||||
# development
|
||||
[patch.crates-io]
|
||||
#ggemini = { path = "ggemini" }
|
||||
#ggemtext = { path = "ggemtext" }
|
||||
ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
||||
|
@ -17,7 +17,7 @@ impl Gemini {
|
||||
// Construct
|
||||
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
|
||||
// Init components
|
||||
let reader = Rc::new(Reader::new(gemtext, base, actions));
|
||||
let reader = Rc::new(Reader::new(gemtext, base, actions).unwrap()); // @TODO handle errors
|
||||
let widget = Rc::new(Widget::new(&reader.widget.text_view));
|
||||
|
||||
// Result
|
||||
|
@ -1,6 +1,8 @@
|
||||
pub mod error;
|
||||
mod tag;
|
||||
mod widget;
|
||||
|
||||
pub use error::Error;
|
||||
use tag::Tag;
|
||||
use widget::Widget;
|
||||
|
||||
@ -32,7 +34,11 @@ pub struct Reader {
|
||||
|
||||
impl Reader {
|
||||
// Construct
|
||||
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
|
||||
pub fn new(
|
||||
gemtext: &str,
|
||||
base: &Uri,
|
||||
actions: (Rc<WindowAction>, Rc<TabAction>),
|
||||
) -> Result<Self, Error> {
|
||||
// Init default values
|
||||
let mut title = None;
|
||||
|
||||
@ -77,36 +83,39 @@ impl Reader {
|
||||
}
|
||||
}
|
||||
Some(ref mut this) => {
|
||||
Code::multiline_continue_from(this, line);
|
||||
match Code::multiline_continue_from(this, line) {
|
||||
Ok(()) => {
|
||||
// Close tag found:
|
||||
if this.completed {
|
||||
// Is alt provided
|
||||
if let Some(alt) = &this.alt {
|
||||
// Insert alt value to the main buffer
|
||||
buffer.insert_with_tags(
|
||||
&mut buffer.end_iter(),
|
||||
alt.as_str(),
|
||||
&[&tag.title.text_tag],
|
||||
);
|
||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
||||
}
|
||||
|
||||
// Close tag found:
|
||||
if this.completed {
|
||||
// Is alt provided
|
||||
if let Some(alt) = &this.alt {
|
||||
// Insert alt value to the main buffer
|
||||
buffer.insert_with_tags(
|
||||
&mut buffer.end_iter(),
|
||||
alt.as_str(),
|
||||
&[&tag.title.text_tag],
|
||||
);
|
||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
||||
// Insert multiline code buffer into main buffer
|
||||
buffer.insert_with_tags(
|
||||
&mut buffer.end_iter(),
|
||||
&this.buffer.join("\n"),
|
||||
&[&tag.code.text_tag],
|
||||
);
|
||||
|
||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
||||
|
||||
// Reset
|
||||
multiline = None;
|
||||
}
|
||||
|
||||
// Skip other actions for this line
|
||||
continue;
|
||||
}
|
||||
|
||||
// Insert multiline code buffer into main buffer
|
||||
buffer.insert_with_tags(
|
||||
&mut buffer.end_iter(),
|
||||
&this.buffer.join("\n"),
|
||||
&[&tag.code.text_tag],
|
||||
);
|
||||
|
||||
buffer.insert(&mut buffer.end_iter(), "\n");
|
||||
|
||||
// Reset
|
||||
multiline = None;
|
||||
Err(e) => return Err(Error::Gemtext(e.to_string())),
|
||||
}
|
||||
|
||||
// Skip other actions for this line
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
@ -351,6 +360,6 @@ impl Reader {
|
||||
}); // @TODO may be expensive for CPU, add timeout?
|
||||
|
||||
// Result
|
||||
Self { title, widget }
|
||||
Ok(Self { title, widget })
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
use std::fmt::{Display, Formatter, Result};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Gemtext(String),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
match self {
|
||||
Self::Gemtext(e) => {
|
||||
write!(f, "Gemtext error: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user