summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-01-18 13:53:45 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-01-18 13:54:19 +1300
commit7dfb8d68c1f596c16702d30ad619160f1a2ecb44 (patch)
tree5ef88c31d02a3ee9df0a66fc10316420819d2465
parent3765c30ef322c31456aa419e970955330a1461ad (diff)
downloadtoaster-7dfb8d68c1f596c16702d30ad619160f1a2ecb44.zip
Fix mailto: links
These were previously being detected only if they begin with ://, which is incorrect and generates incorrect links.
-rw-r--r--src/generate_html.rs19
1 files changed, 12 insertions, 7 deletions
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!("<a href='{path}' class='external'>{label}</a>"));
}