aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJJ2023-06-18 02:23:00 +0000
committerJJ2023-06-18 02:23:44 +0000
commiteee2567e8f9e2f8abf736c79ab12dd5242fab518 (patch)
tree2c3ddc77c32bf463c74c0bc331065fa1011caa9a /src
parent1151e9d5c673dbdf61896094b86373c1a4edf4ab (diff)
minor wikitext display cleanups
Diffstat (limited to 'src')
-rw-r--r--src/display.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/display.rs b/src/display.rs
index 3c372d2..45bbca9 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -15,21 +15,25 @@ const skippable_headers: &[&str; 15] =
pub fn display(definition: String, state: &State) {
let definition = Configuration::default().parse(&definition);
- // impl display on that shit then
- // definition.display(&state.lang);
-
- // this is really quite terrible code
- if !display_language(&definition, &state.lang) {
- display_language(&definition, "");
- }
+ display_language(&definition, &state.lang);
}
// no overloading?? O_O
// matching on an enum of structs SUCKS
// functions as parameters is too hard
-pub fn display_language(definition: &Output, lang: &str) -> bool {
+fn display_language(definition: &Output, lang: &str) {
+ let mut has_lang = false;
+ for (i, node) in definition.nodes.iter().enumerate() {
+ if let Node::Heading { nodes, level, .. } = node
+ && let Some(Node::Text { value, .. }) = nodes.get(0) {
+ if *level == 2 && *value == lang {
+ has_lang = true;
+ break;
+ }
+ }
+ }
+
let mut inside_heading = false;
- let mut correct_language = false;
let mut skipping_heading = false;
for (i, node) in definition.nodes.iter().enumerate() {
@@ -46,9 +50,8 @@ pub fn display_language(definition: &Output, lang: &str) -> bool {
}
print!("\n{}\n", node);
}
- } else if *level == 2 && *value == lang {
+ } else if *level == 2 && (*value == lang || has_lang == false) {
inside_heading = true;
- correct_language = true;
print!("{}", node);
}
} else if inside_heading && !skipping_heading {
@@ -59,9 +62,6 @@ pub fn display_language(definition: &Output, lang: &str) -> bool {
}
}
}
- if correct_language {
- println!();
- }
- return correct_language;
+ println!();
}