diff options
author | metamuffin <metamuffin@disroot.org> | 2022-09-28 23:08:57 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-09-28 23:08:57 +0200 |
commit | 3dbde33c6797c5522929a6b4cc3c62e9f0c27671 (patch) | |
tree | 2d72b5de379f2b0006cb6cb55d4390cf25167ecf | |
parent | d0369e15bf3cc0f61b1997a508187347c39978ef (diff) | |
download | staticwiki-3dbde33c6797c5522929a6b4cc3c62e9f0c27671.tar staticwiki-3dbde33c6797c5522929a6b4cc3c62e9f0c27671.tar.bz2 staticwiki-3dbde33c6797c5522929a6b4cc3c62e9f0c27671.tar.zst |
ref display
-rw-r--r-- | src/main.rs | 36 |
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(¶ms[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>) { |