From: Ruben Beltran del Rio Date: Mon, 13 Jan 2025 17:35:46 +0000 (+0100) Subject: Fix regression where .gmi wasn't being replaced to .html X-Git-Tag: 1.0.1~2 X-Git-Url: https://git.r.bdr.sh/rbdr/gema_texto/commitdiff_plain/5f7e1e310aafc765684463d3ae00359c652cd751?hp=26ab94e7d00cfb920d14b9a6e64dfe16dc120a95 Fix regression where .gmi wasn't being replaced to .html --- diff --git a/Cargo.lock b/Cargo.lock index daf6010..16c047d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 4 [[package]] name = "gema_texto" -version = "1.0.0" +version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index 04e4283..f1c8751 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gema_texto" -version = "1.0.0" +version = "1.0.1" edition = "2021" license = "AGPL-3.0-or-later" description = "Library to parse gemtext and render HTML" diff --git a/README.md b/README.md index 7497cf1..272070e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ for those projects. Here's how each line is handled: - Headings and the content under them is wrapped in a `
` tag. - All text lines are `

`, even empty ones. -- URLs are wrapped in a `

` +- URLs are wrapped in a `

` and .gmi files are changed to .html unless the + URL starts with gemini: - Alt Text is supported for preformatted-toggles, and is written as the aria-label of the `

` tag.
 - Consecutive list items are wrapped in a `
    ` and rendered as `
  • ` tags. diff --git a/src/html_renderer.rs b/src/html_renderer.rs index e513533..503337b 100644 --- a/src/html_renderer.rs +++ b/src/html_renderer.rs @@ -99,8 +99,14 @@ 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 +229,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" ); }