🦠 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking

fix(markdown): Optimise Markdown conversion

fuwn.net a786497c f80e2cd0

verified
+15 -28
+4 -8
src/ast/container.rs
··· 199 // If the Gemtext line starts with an "=" ("=>"), it is a link line, 200 // so splitting it up should be easy enough. 201 let line = line.get(2..).unwrap_or(""); 202 - let mut split = line 203 - .split_whitespace() 204 - .map(String::from) 205 - .collect::<Vec<String>>() 206 - .into_iter(); 207 208 nodes.push(Node::Link { 209 - to: split.next().unwrap_or_default(), 210 text: { 211 - let rest = split.collect::<Vec<String>>().join(" "); 212 213 - if rest.is_empty() { None } else { Some(rest) } 214 }, 215 }); 216
··· 199 // If the Gemtext line starts with an "=" ("=>"), it is a link line, 200 // so splitting it up should be easy enough. 201 let line = line.get(2..).unwrap_or(""); 202 + let mut split = line.split_whitespace(); 203 204 nodes.push(Node::Link { 205 + to: split.next().unwrap_or_default().to_string(), 206 text: { 207 + let rest: Vec<&str> = split.collect(); 208 209 + if rest.is_empty() { None } else { Some(rest.join(" ")) } 210 }, 211 }); 212
+7 -9
src/convert/html.rs
··· 50 ); 51 } 52 Node::List(items) => { 53 - let _ = write!( 54 - &mut html, 55 - "<ul>{}</ul>", 56 - items 57 - .iter() 58 - .map(|i| format!("<li>{i}</li>")) 59 - .collect::<Vec<String>>() 60 - .join("\n") 61 - ); 62 } 63 Node::Blockquote(text) => { 64 let _ = write!(&mut html, "<blockquote>{text}</blockquote>");
··· 50 ); 51 } 52 Node::List(items) => { 53 + let _ = write!(&mut html, "<ul>"); 54 + 55 + for item in items { 56 + let _ = write!(&mut html, "<li>{item}</li>"); 57 + } 58 + 59 + let _ = write!(&mut html, "</ul>"); 60 } 61 Node::Blockquote(text) => { 62 let _ = write!(&mut html, "<blockquote>{text}</blockquote>");
+4 -11
src/convert/markdown.rs
··· 45 text 46 ); 47 } 48 - Node::List(items) => { 49 - let _ = writeln!( 50 - &mut markdown, 51 - "{}", 52 - items 53 - .iter() 54 - .map(|i| format!("- {i}")) 55 - .collect::<Vec<String>>() 56 - .join("\n"), 57 - ); 58 - } 59 Node::Blockquote(text) => { 60 let _ = writeln!(&mut markdown, "> {text}"); 61 }
··· 45 text 46 ); 47 } 48 + Node::List(items) => 49 + for item in items { 50 + let _ = writeln!(&mut markdown, "- {item}"); 51 + }, 52 Node::Blockquote(text) => { 53 let _ = writeln!(&mut markdown, "> {text}"); 54 }