X-Git-Url: https://git.r.bdr.sh/rbdr/gema_texto/blobdiff_plain/8beb2bfa1af988442550c9e6999d924dd14b5236..9d687f8c5a45f72cb0040bb2d0441d04ea9987fb:/src/html_renderer.rs diff --git a/src/html_renderer.rs b/src/html_renderer.rs index e513533..fccf163 100644 --- a/src/html_renderer.rs +++ b/src/html_renderer.rs @@ -99,8 +99,18 @@ fn line_content(line: &GeminiLine) -> String { match line { GeminiLine::Text(content, false) => format!("

{content}

"), GeminiLine::Link(url, text) => { - let display = if text.is_empty() { url } else { text }; - format!("

{display}

") + let processed_url; + if !url.starts_with("gemini:") && url.ends_with(".gmi") { + processed_url = url.replace(".gmi", ".html"); + } else { + processed_url = url.to_string(); + } + let display = if text.is_empty() { + &processed_url + } else { + text + }; + format!("

{display}

") } GeminiLine::Heading(level, content) => format!("{content}"), GeminiLine::ListItem(content) => format!("
  • {content}
  • "), @@ -223,12 +233,18 @@ mod tests { #[test] fn test_links() { let input = vec![ + GeminiLine::Link("gemini://hi.gmi".to_string(), "Example".to_string()), + GeminiLine::Link("/hi.gmi/kidding".to_string(), "Example".to_string()), + GeminiLine::Link("/hi.gmi".to_string(), "Example".to_string()), GeminiLine::Link("https://example.com".to_string(), "Example".to_string()), GeminiLine::Link("https://rust-lang.org".to_string(), String::new()), ]; assert_eq!( render_html(&input), - "

    Example

    \n\ + "

    Example

    \n\ +

    Example

    \n\ +

    Example

    \n\ +

    Example

    \n\

    https://rust-lang.org

    \n" ); }