From 7dfb8d68c1f596c16702d30ad619160f1a2ecb44 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Sat, 18 Jan 2025 13:53:45 +1300 Subject: Fix mailto: links These were previously being detected only if they begin with ://, which is incorrect and generates incorrect links. --- src/generate_html.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/generate_html.rs b/src/generate_html.rs index 9533410..86341e6 100644 --- a/src/generate_html.rs +++ b/src/generate_html.rs @@ -292,7 +292,17 @@ fn line_to_html(line: &Line, page: &Page, website: &Website) -> String { let mut path = path.to_owned(); let mut label = label.to_string(); - if !path.contains("://") { + let mut is_internal = true; + for protocol in ["mailto:", "http://", "https://"] { + if let Some(stripped) = path.strip_prefix(protocol) { + is_internal = false; + if label.is_empty() { + label = stripped.to_string(); + } + } + + } + if is_internal { // Check that the linked static file exists. match website.has_static(page, &path) { Some(resolved_path) => path = resolved_path, @@ -305,13 +315,8 @@ fn line_to_html(line: &Line, page: &Page, website: &Website) -> String { None => path.clone(), }; } - } else if label.is_empty() { - for protocol in ["mailto://", "http://", "https://"] { - if let Some(stripped) = path.strip_prefix(protocol) { - label = stripped.to_string(); - } - } } + let label = sanitize_text(&label); html.push_str(&format!("{label}")); } -- cgit v1.2.3-70-g09d2