aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-01-13 18:35:46 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-01-13 18:35:46 +0100
commit5f7e1e310aafc765684463d3ae00359c652cd751 (patch)
treedcdd4367d440572207103568f53306ebf240a8f9 /src
parent26ab94e7d00cfb920d14b9a6e64dfe16dc120a95 (diff)
Fix regression where .gmi wasn't being replaced to .html
Diffstat (limited to 'src')
-rw-r--r--src/html_renderer.rs18
1 files changed, 15 insertions, 3 deletions
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!("<p>{content}</p>"),
GeminiLine::Link(url, text) => {
- let display = if text.is_empty() { url } else { text };
- format!("<p class=\"a\"><a href=\"{url}\">{display}</a></p>")
+ 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!("<p class=\"a\"><a href=\"{processed_url}\">{display}</a></p>")
}
GeminiLine::Heading(level, content) => format!("<h{level}>{content}</h{level}>"),
GeminiLine::ListItem(content) => format!("<li>{content}</li>"),
@@ -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),
- "<p class=\"a\"><a href=\"https://example.com\">Example</a></p>\n\
+ "<p class=\"a\"><a href=\"gemini://hi.gmi\">Example</a></p>\n\
+ <p class=\"a\"><a href=\"/hi.gmi/kidding\">Example</a></p>\n\
+ <p class=\"a\"><a href=\"/hi.html\">Example</a></p>\n\
+ <p class=\"a\"><a href=\"https://example.com\">Example</a></p>\n\
<p class=\"a\"><a href=\"https://rust-lang.org\">https://rust-lang.org</a></p>\n"
);
}