X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/2cbae13cfd94f48dfe9a8c903e05aea49106b778..5732d284ebc2cc2cbde0f050443b8f137dbf585b:/src/html_renderer.rs diff --git a/src/html_renderer.rs b/src/html_renderer.rs index 47d36bb..1b26bff 100644 --- a/src/html_renderer.rs +++ b/src/html_renderer.rs @@ -1,10 +1,10 @@ use crate::gemini_parser::GeminiLine; /// Renders HTML from a vector of GeminiLine elements. -/// +/// /// # Arguments /// * `lines` - Vector of GeminiLine elements to render -/// +/// /// # Returns /// A String containing the rendered HTML. pub fn render_html(lines: Vec) -> String { @@ -26,23 +26,19 @@ pub fn render_html(lines: Vec) -> String { fn line_preamble( line: &GeminiLine, last_line: Option<&GeminiLine>, - heading_stack: &mut Vec + heading_stack: &mut Vec, ) -> String { let mut html = String::new(); if let Some(last_line) = last_line { match last_line { - GeminiLine::ListItem(_) => { - match line { - GeminiLine::ListItem(_) => {}, - _ => html.push_str("\n"), - } + GeminiLine::ListItem(_) => match line { + GeminiLine::ListItem(_) => {} + _ => html.push_str("\n"), }, - GeminiLine::Quote(_) => { - match line { - GeminiLine::Quote(_) => {}, - _ => html.push_str("\n"), - } + GeminiLine::Quote(_) => match line { + GeminiLine::Quote(_) => {} + _ => html.push_str("\n"), }, _ => {} } @@ -66,18 +62,14 @@ fn line_preamble( } heading_stack.push(*level); html.push_str(&format!("
\n", level)); + } + GeminiLine::ListItem(_) => match last_line { + Some(GeminiLine::ListItem(_)) => {} + _ => html.push_str("
    \n"), }, - GeminiLine::ListItem(_) => { - match last_line { - Some(GeminiLine::ListItem(_)) => {}, - _ => html.push_str("
      \n"), - } - }, - GeminiLine::Quote(_) => { - match last_line { - Some(GeminiLine::Quote(_)) => {}, - _ => html.push_str("
      \n"), - } + GeminiLine::Quote(_) => match last_line { + Some(GeminiLine::Quote(_)) => {} + _ => html.push_str("
      \n"), }, _ => {} } @@ -91,12 +83,14 @@ fn line_content(line: &GeminiLine) -> String { GeminiLine::Link(url, text) => { let display = if text.is_empty() { url } else { text }; format!("

      {}

      ", url, display) - }, + } GeminiLine::Heading(level, content) => format!("{}", level, content, level), GeminiLine::ListItem(content) => format!("
    • {}
    • ", content), - GeminiLine::PreformattedToggle(true, alt_text) => { format!("
      ", alt_text) }
      -        GeminiLine::PreformattedToggle(false, _) => { "
      ".to_string() } - GeminiLine::Text(content, true) | GeminiLine::Quote(content) => format!("{}", content) + GeminiLine::PreformattedToggle(true, alt_text) => { + format!("
      ", alt_text)
      +        }
      +        GeminiLine::PreformattedToggle(false, _) => "
      ".to_string(), + GeminiLine::Text(content, true) | GeminiLine::Quote(content) => content.to_string(), } } @@ -122,13 +116,8 @@ mod tests { #[test] fn test_simple_text() { - let input = vec![ - GeminiLine::Text("Hello world".to_string(), false), - ]; - assert_eq!( - render_html(input), - "

      Hello world

      \n" - ); + let input = vec![GeminiLine::Text("Hello world".to_string(), false)]; + assert_eq!(render_html(input), "

      Hello world

      \n"); } #[test]