aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/container.rs12
-rw-r--r--src/convert/html.rs16
-rw-r--r--src/convert/markdown.rs15
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}");
}