mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
test ggemtext 0.5
This commit is contained in:
parent
39bbfcbdda
commit
1ba127723a
2 changed files with 37 additions and 60 deletions
|
|
@ -32,7 +32,7 @@ version = "0.9.1"
|
||||||
ansi-parser = "0.9.1"
|
ansi-parser = "0.9.1"
|
||||||
anyhow = "1.0.97"
|
anyhow = "1.0.97"
|
||||||
ggemini = "0.17.1"
|
ggemini = "0.17.1"
|
||||||
ggemtext = "0.4.0"
|
ggemtext = "0.5.0"
|
||||||
indexmap = "2.7.0"
|
indexmap = "2.7.0"
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
libspelling = "0.3.0"
|
libspelling = "0.3.0"
|
||||||
|
|
@ -43,7 +43,8 @@ r2d2_sqlite = "0.27.0"
|
||||||
syntect = "5.2.0"
|
syntect = "5.2.0"
|
||||||
|
|
||||||
# development
|
# development
|
||||||
# [patch.crates-io]
|
[patch.crates-io]
|
||||||
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }
|
||||||
# ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
# ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
||||||
|
ggemtext = { git = "https://github.com/YGGverse/ggemtext.git" }
|
||||||
# plurify = { git = "https://github.com/YGGverse/plurify.git" }
|
# plurify = { git = "https://github.com/YGGverse/plurify.git" }
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,9 @@ use tag::Tag;
|
||||||
use super::{ItemAction, WindowAction};
|
use super::{ItemAction, WindowAction};
|
||||||
use crate::app::browser::window::action::Position;
|
use crate::app::browser::window::action::Position;
|
||||||
use ggemtext::line::{
|
use ggemtext::line::{
|
||||||
code::*,
|
code::{self, *},
|
||||||
header::{Header, Level},
|
header::{Header, Level},
|
||||||
link::Link,
|
link::Link,
|
||||||
list::List,
|
|
||||||
quote::Quote,
|
|
||||||
};
|
};
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, RGBA},
|
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY, RGBA},
|
||||||
|
|
@ -31,8 +29,6 @@ use gtk::{
|
||||||
use std::{cell::Cell, collections::HashMap, rc::Rc};
|
use std::{cell::Cell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
pub const DATE_FORMAT: &str = "%Y-%m-%d";
|
pub const DATE_FORMAT: &str = "%Y-%m-%d";
|
||||||
pub const EXTERNAL_LINK_INDICATOR: &str = "⇖";
|
|
||||||
pub const LIST_ITEM: &str = "•";
|
|
||||||
pub const NEW_LINE: &str = "\n";
|
pub const NEW_LINE: &str = "\n";
|
||||||
|
|
||||||
pub struct Gemini {
|
pub struct Gemini {
|
||||||
|
|
@ -108,8 +104,7 @@ impl Gemini {
|
||||||
let is_multiline_enabled = {
|
let is_multiline_enabled = {
|
||||||
let mut t: usize = 0;
|
let mut t: usize = 0;
|
||||||
for l in gemtext.lines() {
|
for l in gemtext.lines() {
|
||||||
if (l.starts_with(multiline::TAG) || l.ends_with(multiline::TAG))
|
if (l.starts_with(code::TAG) || l.ends_with(code::TAG)) && Inline::from(l).is_none()
|
||||||
&& Inline::from(l).is_none()
|
|
||||||
{
|
{
|
||||||
t += 1;
|
t += 1;
|
||||||
}
|
}
|
||||||
|
|
@ -149,11 +144,7 @@ impl Gemini {
|
||||||
}
|
}
|
||||||
} // @TODO handle
|
} // @TODO handle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append new line
|
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Skip other actions for this line
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -242,8 +233,7 @@ impl Gemini {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is header
|
// Is header
|
||||||
if let Some(header) = Header::from(line) {
|
if let Some(header) = Header::parse(line) {
|
||||||
// Append value to buffer
|
|
||||||
buffer.insert_with_tags(
|
buffer.insert_with_tags(
|
||||||
&mut buffer.end_iter(),
|
&mut buffer.end_iter(),
|
||||||
&header.value,
|
&header.value,
|
||||||
|
|
@ -255,40 +245,32 @@ impl Gemini {
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Update reader title using first gemtext header match
|
|
||||||
if title.is_none() {
|
if title.is_none() {
|
||||||
title = Some(header.value.clone());
|
title = Some(header.value.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip other actions for this line
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is link
|
// Is link
|
||||||
if let Some(link) = Link::from(line, Some(base), Some(&TimeZone::local())) {
|
if let Some(link) = Link::from(line, Some(base), Some(&TimeZone::local())) {
|
||||||
// Create vector for alt values
|
|
||||||
let mut alt = Vec::new();
|
let mut alt = Vec::new();
|
||||||
|
|
||||||
// Append external indicator on exist
|
|
||||||
if link.uri.scheme() != base.scheme() {
|
if link.uri.scheme() != base.scheme() {
|
||||||
alt.push(EXTERNAL_LINK_INDICATOR.to_string());
|
alt.push("⇖".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append date on exist
|
if let Some(t) = link.timestamp {
|
||||||
if let Some(timestamp) = link.timestamp {
|
|
||||||
// https://docs.gtk.org/glib/method.DateTime.format.html
|
// https://docs.gtk.org/glib/method.DateTime.format.html
|
||||||
if let Ok(value) = timestamp.format(DATE_FORMAT) {
|
if let Ok(f) = t.format(DATE_FORMAT) {
|
||||||
alt.push(value.to_string())
|
alt.push(f.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append alt value on exist or use URL
|
|
||||||
alt.push(match link.alt {
|
alt.push(match link.alt {
|
||||||
Some(alt) => alt.to_string(),
|
Some(alt) => alt.to_string(),
|
||||||
None => link.uri.to_string(),
|
None => link.uri.to_string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create new tag for new link
|
|
||||||
let a = TextTag::builder()
|
let a = TextTag::builder()
|
||||||
.foreground_rgba(&link_color.0)
|
.foreground_rgba(&link_color.0)
|
||||||
// .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+
|
// .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+
|
||||||
|
|
@ -296,38 +278,35 @@ impl Gemini {
|
||||||
.wrap_mode(WrapMode::Word)
|
.wrap_mode(WrapMode::Word)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
// Register new tag
|
|
||||||
if !tag.text_tag_table.add(&a) {
|
if !tag.text_tag_table.add(&a) {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append alt vector values to buffer
|
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
|
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Append tag to HashMap storage
|
|
||||||
links.insert(a, link.uri.clone());
|
links.insert(a, link.uri.clone());
|
||||||
|
|
||||||
// Skip other actions for this line
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is list
|
// Is list
|
||||||
if let Some(list) = List::from(line) {
|
{
|
||||||
// Append value to buffer
|
use ggemtext::line::list::Gemtext;
|
||||||
|
if let Some(value) = line.as_value() {
|
||||||
buffer.insert_with_tags(
|
buffer.insert_with_tags(
|
||||||
&mut buffer.end_iter(),
|
&mut buffer.end_iter(),
|
||||||
format!("{LIST_ITEM} {}", list.value).as_str(),
|
&format!("• {value}"),
|
||||||
&[&tag.list],
|
&[&tag.list],
|
||||||
);
|
);
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
|
||||||
// Skip other actions for this line
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Is quote
|
// Is quote
|
||||||
if let Some(quote) = Quote::from(line) {
|
{
|
||||||
|
use ggemtext::line::quote::Gemtext;
|
||||||
|
if let Some(quote) = line.as_value() {
|
||||||
// Show quote indicator if last line is not quote (to prevent duplicates)
|
// Show quote indicator if last line is not quote (to prevent duplicates)
|
||||||
if !is_line_after_quote {
|
if !is_line_after_quote {
|
||||||
// Show only if the icons resolved for default `Display`
|
// Show only if the icons resolved for default `Display`
|
||||||
|
|
@ -336,17 +315,14 @@ impl Gemini {
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is_line_after_quote = true;
|
buffer.insert_with_tags(&mut buffer.end_iter(), quote, &[&tag.quote]);
|
||||||
|
|
||||||
// Append value to buffer
|
|
||||||
buffer.insert_with_tags(&mut buffer.end_iter(), "e.value, &[&tag.quote]);
|
|
||||||
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
|
||||||
|
is_line_after_quote = true;
|
||||||
// Skip other actions for this line
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
is_line_after_quote = false;
|
is_line_after_quote = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Nothing match custom tags above,
|
// Nothing match custom tags above,
|
||||||
// just append plain text covered in empty tag (to handle controller events properly)
|
// just append plain text covered in empty tag (to handle controller events properly)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue