diff options
| author | Fuwn <[email protected]> | 2025-09-11 06:18:36 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-09-11 06:18:36 +0000 |
| commit | a786497ce0255e1ca2dcdcab46030786c1b9e98e (patch) | |
| tree | c50126f55d4b8a703b2791fc4a264a4bccc828d2 /src | |
| parent | fix(meta): Better comply with RFC 2045 (diff) | |
| download | germ-a786497ce0255e1ca2dcdcab46030786c1b9e98e.tar.xz germ-a786497ce0255e1ca2dcdcab46030786c1b9e98e.zip | |
fix(markdown): Optimise Markdown conversion
Diffstat (limited to 'src')
| -rw-r--r-- | src/ast/container.rs | 12 | ||||
| -rw-r--r-- | src/convert/html.rs | 16 | ||||
| -rw-r--r-- | src/convert/markdown.rs | 15 |
3 files changed, 15 insertions, 28 deletions
diff --git a/src/ast/container.rs b/src/ast/container.rs index 46c548b..fe4f949 100644 --- a/src/ast/container.rs +++ b/src/ast/container.rs @@ -199,18 +199,14 @@ impl Ast { // If the Gemtext line starts with an "=" ("=>"), it is a link line, // so splitting it up should be easy enough. let line = line.get(2..).unwrap_or(""); - let mut split = line - .split_whitespace() - .map(String::from) - .collect::<Vec<String>>() - .into_iter(); + let mut split = line.split_whitespace(); nodes.push(Node::Link { - to: split.next().unwrap_or_default(), + to: split.next().unwrap_or_default().to_string(), text: { - let rest = split.collect::<Vec<String>>().join(" "); + let rest: Vec<&str> = split.collect(); - if rest.is_empty() { None } else { Some(rest) } + if rest.is_empty() { None } else { Some(rest.join(" ")) } }, }); diff --git a/src/convert/html.rs b/src/convert/html.rs index bfba6e7..1927c86 100644 --- a/src/convert/html.rs +++ b/src/convert/html.rs @@ -50,15 +50,13 @@ pub fn convert(source: &[Node]) -> String { ); } Node::List(items) => { - let _ = write!( - &mut html, - "<ul>{}</ul>", - items - .iter() - .map(|i| format!("<li>{i}</li>")) - .collect::<Vec<String>>() - .join("\n") - ); + let _ = write!(&mut html, "<ul>"); + + for item in items { + let _ = write!(&mut html, "<li>{item}</li>"); + } + + let _ = write!(&mut html, "</ul>"); } Node::Blockquote(text) => { let _ = write!(&mut html, "<blockquote>{text}</blockquote>"); diff --git a/src/convert/markdown.rs b/src/convert/markdown.rs index 27306a7..0dac611 100644 --- a/src/convert/markdown.rs +++ b/src/convert/markdown.rs @@ -45,17 +45,10 @@ pub fn convert(source: &[Node]) -> String { text ); } - Node::List(items) => { - let _ = writeln!( - &mut markdown, - "{}", - items - .iter() - .map(|i| format!("- {i}")) - .collect::<Vec<String>>() - .join("\n"), - ); - } + Node::List(items) => + for item in items { + let _ = writeln!(&mut markdown, "- {item}"); + }, Node::Blockquote(text) => { let _ = writeln!(&mut markdown, "> {text}"); } |