diff options
| author | Fuwn <[email protected]> | 2024-07-27 06:11:37 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-07-27 06:11:41 +0000 |
| commit | 48c9004eaea72d18c18dd22be4c4f7d99be0eca5 (patch) | |
| tree | 5b82ac4769162ddb2dee2c143f028569a1789a24 /src | |
| parent | chore(docker): sync rustc release (diff) | |
| download | september-48c9004eaea72d18c18dd22be4c4f7d99be0eca5.tar.xz september-48c9004eaea72d18c18dd22be4c4f7d99be0eca5.zip | |
feat(html): clear adjacent link indicators
Diffstat (limited to 'src')
| -rw-r--r-- | src/html.rs | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/src/html.rs b/src/html.rs index e9d0b96..8efd7d9 100644 --- a/src/html.rs +++ b/src/html.rs @@ -28,6 +28,7 @@ pub fn from_gemini( let mut html = String::new(); let mut title = String::new(); let mut previous_link = false; + let mut previous_link_count = 0; let condense_links = { let links = var("CONDENSE_LINKS").map_or_else( |_| vec![], @@ -52,14 +53,51 @@ pub fn from_gemini( in_condense_links_flag_trap = true; } + let align_adjacent_links = |html: &str| { + if previous_link_count > 0 { + html + .chars() + .rev() + .collect::<String>() + .replacen( + &r#"<span class="gemini-fragment">=></span> "# + .chars() + .rev() + .collect::<String>(), + "", + 1, + ) + .chars() + .rev() + .collect::<String>() + } else { + html.to_string() + } + }; + if previous_link && (!matches!(node, Node::Link { .. }) || (!condense_links && !in_condense_links_flag_trap)) { - html.push_str("\n</p>"); + if let Some(next) = ast.iter().skip_while(|n| n != &node).nth(1) { + if matches!(next, Node::Link { .. }) || previous_link { + html.push_str("<br />"); + } else { + html.push_str("</p>"); + } + } else { + html.push_str("</p>"); + } + previous_link = false; + html = align_adjacent_links(&html); + previous_link_count = 0; } else if previous_link { + html = align_adjacent_links(&html); + html.push_str(" <span style=\"opacity: 50%;\">|</span> "); + + previous_link_count += 1; } else if !previous_link && matches!(node, Node::Link { .. }) { html.push_str("<p>"); } @@ -184,7 +222,12 @@ pub fn from_gemini( previous_link = true; html.push_str(&format!( - "<a href=\"{}\">{}</a>", + r#"{}<a href="{}">{}</a>"#, + if condense_links { + "" + } else { + r#"<span class="gemini-fragment">=></span> "# + }, href, safe(text.as_ref().unwrap_or(to)), )); |