From 4d1fa804ba81c27e2428114b38787d62e1c6cc4f Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 26 Jun 2025 20:53:15 +0300 Subject: [PATCH] add missed trailing slash condition based on the current url --- .../window/tab/item/page/content/text/nex.rs | 74 ++++++++++--------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/src/app/browser/window/tab/item/page/content/text/nex.rs b/src/app/browser/window/tab/item/page/content/text/nex.rs index 8b6af1c4..c2d9b2ef 100644 --- a/src/app/browser/window/tab/item/page/content/text/nex.rs +++ b/src/app/browser/window/tab/item/page/content/text/nex.rs @@ -51,41 +51,49 @@ impl Nex for TextView { // Collect links for line in data.lines() { - // just borrow ggemtext parser as compatible API - if let Some(link) = ggemtext::line::Link::parse(line) { - if let Some(uri) = link.uri(Some(base)) { - let a = TextTag::builder() - .foreground_rgba(&link_color.0) - // .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+ - .sentence(true) - .wrap_mode(WrapMode::Word) - .build(); + // * skip links processing when the current location does not contain trailing slash + // it may be confusing: gemini://bbs.geminispace.org/s/nex/29641 + if base.to_string().ends_with("/") { + // just borrow ggemtext parser as compatible API + if let Some(link) = ggemtext::line::Link::parse(line) { + if let Some(uri) = link.uri(Some(base)) { + let a = TextTag::builder() + .foreground_rgba(&link_color.0) + // .foreground_rgba(&adw::StyleManager::default().accent_color_rgba()) @TODO adw 1.6 / ubuntu 24.10+ + .sentence(true) + .wrap_mode(WrapMode::Word) + .build(); - if !tags.add(&a) { - panic!() + if !tags.add(&a) { + panic!() + } + + buffer.insert_with_tags( + &mut buffer.end_iter(), + &format!( + "{} {}", + if uri.scheme() == base.scheme() { + "=>" + } else { + "<=" + }, + link.url + ), + &[&a], + ); + if let Some(alt) = link.alt { + buffer.insert_with_tags( + &mut buffer.end_iter(), + &format!(" {alt}"), + &[&p], + ); + } + buffer.insert(&mut buffer.end_iter(), NEW_LINE); + + links.insert(a, uri); + + continue; } - - buffer.insert_with_tags( - &mut buffer.end_iter(), - &format!( - "{} {}", - if uri.scheme() == base.scheme() { - "=>" - } else { - "<=" - }, - link.url - ), - &[&a], - ); - if let Some(alt) = link.alt { - buffer.insert_with_tags(&mut buffer.end_iter(), &format!(" {alt}"), &[&p]); - } - buffer.insert(&mut buffer.end_iter(), NEW_LINE); - - links.insert(a, uri); - - continue; } } // Nothing match custom tags above,