X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/5732d284ebc2cc2cbde0f050443b8f137dbf585b..f08e8d64dce087201089d2b3276b3dfcdb000173:/src/gemini_parser.rs diff --git a/src/gemini_parser.rs b/src/gemini_parser.rs index e6de4ec..f7aa0cc 100644 --- a/src/gemini_parser.rs +++ b/src/gemini_parser.rs @@ -8,7 +8,7 @@ pub enum GeminiLine { ListItem(String), } -/// Parses gemtext source code into a vector of GeminiLine elements. +/// Parses gemtext source code into a vector of `GeminiLine` elements. /// /// # Arguments /// * `source` - A string slice that contains the gemtext @@ -47,7 +47,7 @@ fn parse_line(line: &str) -> GeminiLine { match line { s if s.starts_with("###") => GeminiLine::Heading(3, s[3..].to_string()), s if s.starts_with("##") => GeminiLine::Heading(2, s[2..].to_string()), - s if s.starts_with("#") => GeminiLine::Heading(1, s[1..].to_string()), + s if s.starts_with('#') => GeminiLine::Heading(1, s[1..].to_string()), s if s.starts_with("=>") => { let content = s[2..].trim(); match content.split_once(char::is_whitespace) { @@ -58,7 +58,7 @@ fn parse_line(line: &str) -> GeminiLine { } } s if s.starts_with("* ") => GeminiLine::ListItem(s[2..].to_string()), - s if s.starts_with(">") => GeminiLine::Quote(s[1..].to_string()), + s if s.starts_with('>') => GeminiLine::Quote(s[1..].to_string()), s if s.starts_with("```") => GeminiLine::PreformattedToggle(true, s[3..].to_string()), _ => GeminiLine::Text(line.to_string(), false), } @@ -82,7 +82,7 @@ mod tests { parse_line("# Heading"), GeminiLine::Heading(1, " Heading".to_string()) ); - assert_eq!(parse_line("###"), GeminiLine::Heading(3, "".to_string())); + assert_eq!(parse_line("###"), GeminiLine::Heading(3, String::new())); assert_eq!( parse_line("#####"), GeminiLine::Heading(3, "##".to_string()) @@ -111,16 +111,16 @@ mod tests { ); assert_eq!( parse_line("=> /local/path"), - GeminiLine::Link("/local/path".to_string(), "".to_string()) + GeminiLine::Link("/local/path".to_string(), String::new()) ); assert_eq!( parse_line("=>"), - GeminiLine::Link("".to_string(), "".to_string()) + GeminiLine::Link(String::new(), String::new()) ); assert_eq!( parse_line("=> "), - GeminiLine::Link("".to_string(), "".to_string()) + GeminiLine::Link(String::new(), String::new()) ); assert_eq!( parse_line("=> multiple spaces in text"), @@ -140,7 +140,7 @@ mod tests { GeminiLine::ListItem("List item".to_string()) ); - assert_eq!(parse_line("* "), GeminiLine::ListItem("".to_string())); + assert_eq!(parse_line("* "), GeminiLine::ListItem(String::new())); assert_eq!(parse_line("*"), GeminiLine::Text("*".to_string(), false)); assert_eq!( parse_line("*WithText"), @@ -159,7 +159,7 @@ mod tests { GeminiLine::Quote("Quote text".to_string()) ); - assert_eq!(parse_line(">"), GeminiLine::Quote("".to_string())); + assert_eq!(parse_line(">"), GeminiLine::Quote(String::new())); assert_eq!(parse_line("> "), GeminiLine::Quote(" ".to_string())); assert_eq!( parse_line(">>Nested"), @@ -176,7 +176,7 @@ mod tests { assert_eq!( parse_line("```"), - GeminiLine::PreformattedToggle(true, "".to_string()) + GeminiLine::PreformattedToggle(true, String::new()) ); assert_eq!( parse_line("``` "), @@ -189,11 +189,11 @@ mod tests { assert_eq!( parse_preformatted_line("```alt-text"), - GeminiLine::PreformattedToggle(false, "".to_string()) + GeminiLine::PreformattedToggle(false, String::new()) ); assert_eq!( parse_preformatted_line("```"), - GeminiLine::PreformattedToggle(false, "".to_string()) + GeminiLine::PreformattedToggle(false, String::new()) ); } @@ -206,7 +206,7 @@ mod tests { ); // Edge cases - assert_eq!(parse_line(""), GeminiLine::Text("".to_string(), false)); + assert_eq!(parse_line(""), GeminiLine::Text(String::new(), false)); assert_eq!(parse_line(" "), GeminiLine::Text(" ".to_string(), false)); assert_eq!(parse_line(" "), GeminiLine::Text(" ".to_string(), false)); } @@ -265,7 +265,7 @@ code GeminiLine::Text("=> https://example.com Link text".to_string(), true), GeminiLine::Text("* List item".to_string(), true), GeminiLine::Text(">Quote".to_string(), true), - GeminiLine::PreformattedToggle(false, "".to_string()), + GeminiLine::PreformattedToggle(false, String::new()), ] ); }