update ggemtext api, test repository version

This commit is contained in:
yggverse 2025-03-21 17:16:58 +02:00
parent d469499d46
commit d1623bda9e
2 changed files with 20 additions and 63 deletions

View file

@ -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.3" ggemini = "0.17.3"
ggemtext = "0.5.0" ggemtext = "0.6.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"
@ -45,5 +45,5 @@ 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" }
# plurify = { git = "https://github.com/YGGverse/plurify.git" } # plurify = { git = "https://github.com/YGGverse/plurify.git" }

View file

@ -49,8 +49,8 @@ impl Gemini {
// * maybe less expensive than update entire HashMap by iter // * maybe less expensive than update entire HashMap by iter
let hover: Rc<Cell<Option<TextTag>>> = Rc::new(Cell::new(None)); let hover: Rc<Cell<Option<TextTag>>> = Rc::new(Cell::new(None));
// Init multiline code builder features // Init code features
let mut multiline = None; let mut code = None;
// Init quote icon feature // Init quote icon feature
let mut is_line_after_quote = false; let mut is_line_after_quote = false;
@ -93,15 +93,13 @@ impl Gemini {
// 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 multiline format on at least one closing tag not found // Disable code format on at least one closing tag not found
// gemini://bbs.geminispace.org/s/Gemini/26031 // gemini://bbs.geminispace.org/s/Gemini/26031
let is_multiline_enabled = { let is_code_enabled = {
use ggemtext::line::code::{self}; use ggemtext::line::code::{self};
let mut t: usize = 0; let mut t: usize = 0;
for l in gemtext.lines() { for l in gemtext.lines() {
if (l.starts_with(code::TAG) || l.ends_with(code::TAG)) if l.starts_with(code::TAG) {
&& code::inline::Gemtext::as_value(l).is_none()
{
t += 1; t += 1;
} }
} }
@ -110,67 +108,26 @@ impl Gemini {
// Parse gemtext lines // Parse gemtext lines
for line in gemtext.lines() { for line in gemtext.lines() {
// Is inline code if is_code_enabled {
{ use ggemtext::line::Code;
if let Some(code) = ggemtext::line::code::inline::Gemtext::as_value(line) { match code {
// Try auto-detect code syntax for given `value` @TODO optional
match syntax.highlight(code, None) {
Ok(highlight) => {
for (syntax_tag, entity) in highlight {
// Register new tag
if !tag.text_tag_table.add(&syntax_tag) {
todo!()
}
// Append tag to buffer
buffer.insert_with_tags(
&mut buffer.end_iter(),
&entity,
&[&syntax_tag],
);
}
}
Err(_) => {
// Try ANSI/SGR format (terminal emulation) @TODO optional
for (ansi_tag, entity) in ansi::format(code) {
// Register new tag
if !tag.text_tag_table.add(&ansi_tag) {
todo!()
}
// Append tag to buffer
buffer.insert_with_tags(
&mut buffer.end_iter(),
&entity,
&[&ansi_tag],
);
}
} // @TODO handle
}
buffer.insert(&mut buffer.end_iter(), NEW_LINE);
continue;
}
}
// Is multiline code
if is_multiline_enabled {
use ggemtext::line::code::Multiline;
match multiline {
None => { None => {
// Open tag found // Open tag found
if let Some(code) = Multiline::begin_from(line) { if let Some(c) = Code::begin_from(line) {
// Begin next lines collection into the code buffer // Begin next lines collection into the code buffer
multiline = Some(code); code = Some(c);
// Skip other actions for this line // Skip other actions for this line
continue; continue;
} }
} }
Some(ref mut this) => { Some(ref mut c) => {
match Multiline::continue_from(this, line) { match c.continue_from(line) {
Ok(()) => { Ok(()) => {
// Close tag found: // Close tag found:
if this.completed { if c.is_completed {
// Is alt provided // Is alt provided
let alt = match this.alt { let alt = match c.alt {
Some(ref alt) => { Some(ref alt) => {
// Insert alt value to the main buffer // Insert alt value to the main buffer
buffer.insert_with_tags( buffer.insert_with_tags(
@ -190,7 +147,7 @@ impl Gemini {
// Begin code block construction // Begin code block construction
// Try auto-detect code syntax for given `value` and `alt` @TODO optional // Try auto-detect code syntax for given `value` and `alt` @TODO optional
match syntax.highlight(&this.value, alt) { match syntax.highlight(&c.value, alt) {
Ok(highlight) => { Ok(highlight) => {
for (syntax_tag, entity) in highlight { for (syntax_tag, entity) in highlight {
// Register new tag // Register new tag
@ -207,7 +164,7 @@ impl Gemini {
} }
Err(_) => { Err(_) => {
// Try ANSI/SGR format (terminal emulation) @TODO optional // Try ANSI/SGR format (terminal emulation) @TODO optional
for (syntax_tag, entity) in ansi::format(&this.value) { for (syntax_tag, entity) in ansi::format(&c.value) {
// Register new tag // Register new tag
if !tag.text_tag_table.add(&syntax_tag) { if !tag.text_tag_table.add(&syntax_tag) {
todo!() todo!()
@ -223,7 +180,7 @@ impl Gemini {
} }
// Reset // Reset
multiline = None; code = None;
} }
// Skip other actions for this line // Skip other actions for this line
@ -465,7 +422,7 @@ impl Gemini {
}); // @TODO may be expensive for CPU, add timeout? }); // @TODO may be expensive for CPU, add timeout?
// Result // Result
if is_multiline_enabled { if is_code_enabled {
Ok(Self { text_view, title }) Ok(Self { text_view, title })
} else { } else {
Err(Error::Markup( Err(Error::Markup(