aboutsummaryrefslogtreecommitdiff
path: root/src/convert
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-05-18 06:24:50 +0000
committerFuwn <[email protected]>2023-05-18 06:24:50 +0000
commit56f53ddca0135e17708af585bfb50144d6836f55 (patch)
tree1d5beea4c266a7d9bdd50fe4750540d618b0b160 /src/convert
parentfix: improve macro hygiene (diff)
downloadgerm-56f53ddca0135e17708af585bfb50144d6836f55.tar.xz
germ-56f53ddca0135e17708af585bfb50144d6836f55.zip
fmt: update rustfmt.toml
Diffstat (limited to 'src/convert')
-rw-r--r--src/convert/html.rs31
-rw-r--r--src/convert/markdown.rs39
2 files changed, 25 insertions, 45 deletions
diff --git a/src/convert/html.rs b/src/convert/html.rs
index 581cbab..a6b0426 100644
--- a/src/convert/html.rs
+++ b/src/convert/html.rs
@@ -26,20 +26,14 @@ pub fn convert(source: &[Node]) -> String {
for node in source {
match node {
Node::Text(text) => html.push_str(&format!("<p>{text}</p>")),
- Node::Link {
- to,
- text,
- } => {
+ Node::Link { to, text } => {
html.push_str(&format!(
"<a href=\"{}\">{}</a><br>",
to,
text.clone().unwrap_or_else(|| to.clone())
));
}
- Node::Heading {
- level,
- text,
- } => {
+ Node::Heading { level, text } => {
html.push_str(&format!(
"<{}>{}</{0}>",
match level {
@@ -51,20 +45,17 @@ pub fn convert(source: &[Node]) -> String {
text
));
}
- Node::List(items) =>
- html.push_str(&format!(
- "<ul>{}</ul>",
- items
- .iter()
- .map(|i| format!("<li>{i}</li>"))
- .collect::<Vec<String>>()
- .join("\n")
- )),
+ Node::List(items) => html.push_str(&format!(
+ "<ul>{}</ul>",
+ items
+ .iter()
+ .map(|i| format!("<li>{i}</li>"))
+ .collect::<Vec<String>>()
+ .join("\n")
+ )),
Node::Blockquote(text) =>
html.push_str(&format!("<blockquote>{text}</blockquote>")),
- Node::PreformattedText {
- text, ..
- } => {
+ Node::PreformattedText { text, .. } => {
html.push_str(&format!("<pre>{text}</pre>"));
}
Node::Whitespace => {}
diff --git a/src/convert/markdown.rs b/src/convert/markdown.rs
index 3401940..71e54f2 100644
--- a/src/convert/markdown.rs
+++ b/src/convert/markdown.rs
@@ -26,18 +26,11 @@ pub fn convert(source: &[Node]) -> String {
for node in source {
match node {
Node::Text(text) => markdown.push_str(&format!("{text}\n")),
- Node::Link {
- to,
- text,
- } =>
- markdown.push_str(&text.clone().map_or_else(
- || format!("<{to}>\n"),
- |text| format!("[{text}]({to})\n"),
- )),
- Node::Heading {
- level,
- text,
- } => {
+ Node::Link { to, text } => markdown.push_str(&text.clone().map_or_else(
+ || format!("<{to}>\n"),
+ |text| format!("[{text}]({to})\n"),
+ )),
+ Node::Heading { level, text } => {
markdown.push_str(&format!(
"{} {}\n",
match level {
@@ -49,20 +42,16 @@ pub fn convert(source: &[Node]) -> String {
text
));
}
- Node::List(items) =>
- markdown.push_str(&format!(
- "{}\n",
- items
- .iter()
- .map(|i| format!("- {i}"))
- .collect::<Vec<String>>()
- .join("\n"),
- )),
+ Node::List(items) => markdown.push_str(&format!(
+ "{}\n",
+ items
+ .iter()
+ .map(|i| format!("- {i}"))
+ .collect::<Vec<String>>()
+ .join("\n"),
+ )),
Node::Blockquote(text) => markdown.push_str(&format!("> {text}\n")),
- Node::PreformattedText {
- alt_text,
- text,
- } => {
+ Node::PreformattedText { alt_text, text } => {
markdown.push_str(&format!(
"```{}\n{}```\n",
alt_text.clone().unwrap_or_default(),