diff options
Diffstat (limited to 'src/gemini_to_html.rs')
| -rw-r--r-- | src/gemini_to_html.rs | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/src/gemini_to_html.rs b/src/gemini_to_html.rs index 845c568..8359cfe 100644 --- a/src/gemini_to_html.rs +++ b/src/gemini_to_html.rs @@ -47,22 +47,19 @@ pub fn gemini_to_html( )); let ast = ast_tree.inner(); let mut html = String::new(); - let mut title = "".to_string(); + let mut title = String::new(); for node in ast { match node { - Node::Text(text) => html.push_str(&format!("<p>{}</p>", text)), - Node::Link { - to, - text, - } => { + Node::Text(text) => html.push_str(&format!("<p>{text}</p>")), + Node::Link { to, text } => { let mut href = to.clone(); let mut surface = false; if href.contains("://") && !href.starts_with("gemini://") { surface = true; } else if !href.starts_with("gemini://") && !href.starts_with('/') { - href = format!("./{}", href); + href = format!("./{href}"); } else if href.starts_with('/') || !href.contains("://") { href = link_from_host_href(url, &href); } @@ -78,7 +75,7 @@ pub fn gemini_to_html( .trim_end_matches('/') .split('/') .collect::<Vec<_>>() - .get(0) + .first() .unwrap() != &url.authority.host.as_str() { @@ -115,13 +112,10 @@ pub fn gemini_to_html( html.push_str(&format!( "<p><a href=\"{}\">{}</a></p>\n", href, - text.clone().unwrap_or_else(|| "".to_string()) + text.clone().unwrap_or_default() )); } - Node::Heading { - level, - text, - } => { + Node::Heading { level, text } => { if title.is_empty() && *level == 1 { title = text.clone(); } @@ -137,21 +131,19 @@ pub fn gemini_to_html( text )); } - Node::List(items) => - html.push_str(&format!( - "<ul>{}</ul>", - items - .iter() - .map(|i| format!("<li>{}</li>", i)) - .collect::<Vec<String>>() - .join("\n") - )), - Node::Blockquote(text) => - html.push_str(&format!("<blockquote>{}</blockquote>", text)), - Node::PreformattedText { - text, .. - } => { - html.push_str(&format!("<pre>{}</pre>", text)); + Node::List(items) => html.push_str(&format!( + "<ul>{}</ul>", + items + .iter() + .map(|i| format!("<li>{i}</li>")) + .collect::<Vec<String>>() + .join("\n") + )), + Node::Blockquote(text) => { + html.push_str(&format!("<blockquote>{text}</blockquote>")); + } + Node::PreformattedText { text, .. } => { + html.push_str(&format!("<pre>{text}</pre>")); } Node::Whitespace => {} } |