aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index eb2f70f..6af1908 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -207,16 +207,16 @@ fn render_node(html: &mut String, refs: &mut Vec<String>, n: &Node) {
write!(html, "<sup><a href=\"#{}\">[{}]</a></sup>", refid, refid).unwrap();
}
}
- _ => write!(html, "[todo: tag {name:?} template]").unwrap(),
+ _ => write!(html, "[todo: {name:?} tag]").unwrap(),
},
parse_wiki_text::Node::Template {
name, parameters, ..
} => {
let name = match name.first() {
Some(Node::Text { value, .. }) => value,
- _ => panic!("no"),
+ _ => "",
};
- render_template(html, refs, name, parameters)
+ render_template(html, refs, name, parameters);
}
parse_wiki_text::Node::Text { value, .. } => write!(html, "{}", escape(value)).unwrap(),
}
@@ -253,9 +253,10 @@ pub fn render_template(
refs: &mut Vec<String>,
name: &str,
params: &Vec<Parameter>,
-) {
+) -> Option<()> {
use std::fmt::Write;
match name {
+ // TODO this can panic
"lang" => write!(html, "{}", render_nodes_to_string(&params[1].value, refs)).unwrap(),
"IPA" => write!(
html,
@@ -264,12 +265,37 @@ pub fn render_template(
)
.unwrap(),
+ "Internetquelle" | "Literatur" => {
+ write!(html, "{}: <ul>", escape(name)).unwrap();
+ for p in params {
+ write!(
+ html,
+ "<li>{}: {}</li>",
+ p.name
+ .as_ref()
+ .map(|n| render_nodes_to_string(n, &mut vec![]))
+ .unwrap_or(String::from("??")),
+ render_nodes_to_string(&p.value, &mut vec![])
+ )
+ .unwrap();
+ }
+ write!(html, "</ul>").unwrap();
+ }
+
_ => {
- write!(html, "[todo: {name:?} template]").unwrap();
+ write!(html, "[todo: {name:?} template <pre>{params:#?}</pre>]").unwrap();
// eprintln!("unsupported template {name:?}");
// eprintln!("{params:?}");
}
}
+ Some(())
+}
+
+pub fn text_node(n: &Node) -> String {
+ match n {
+ Node::Text { value, .. } => value.to_string(),
+ _ => String::from("[todo: fix this bug :) ]"),
+ }
}
fn render_refs(html: &mut String, refs: &Vec<String>) {