diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/src/main.rs b/src/main.rs index 597ebdf..ce352d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1066,36 +1066,15 @@ fn format_batch_aux<'a>( } writeln!(f, "<hr />")?; - writeln!( - f, - r#"<details><summary>Extra vocabulary (this level)</summary>"# - )?; - for v in batch.extra_vocab.iter() { - if batch.level.contains(&v.level) { - writeln!( - f, - r#"<p>({}) {} [{}] {}</p>"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"</details>"#)?; - if !batch.level.contains("N4") { - writeln!( - f, - r#"<details><summary>Extra vocabulary (previous levels)</summary>"# - )?; - for v in batch.extra_vocab.iter() { - if !batch.level.contains(&v.level) { - writeln!( - f, - r#"<p>({}) {} [{}] {}</p>"#, - v.level, v.kanji, v.kana, v.en - )?; - } - } - writeln!(f, r#"</details>"#)?; - } + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| batch.level.contains(&v.level)).collect::<Vec<_>>(), + "Extra vocabulary (this level)")?; + format_vocab( + &mut f, + &batch.extra_vocab.iter().filter(|v| !batch.level.contains(&v.level)).collect::<Vec<_>>(), + "Extra vocabulary (previous levels)")?; + writeln!(f, "<hr />")?; writeln!(f, "<p>\(≧▽≦)/</p>")?; @@ -1104,6 +1083,21 @@ fn format_batch_aux<'a>( Ok(()) } +fn format_vocab(f: &mut impl Write, vocab: &[&JlptVocab], t: &str) -> Result<()> { + if !vocab.is_empty() { + writeln!(f, r#"<details><summary>{}</summary><table class="vocabtable">"#, t)?; + for v in vocab { + writeln!( + f, + r#"<tr><td>{}</td><td> <span style="font-size: 1.2em">{}</span> </td><td>{}</td><td>{}</td></tr>"#, + v.level, v.kanji, v.en, v.kana + )?; + } + writeln!(f, "</table></details>")?; + } + Ok(()) +} + fn expl_clean_word(w: &str) -> (&str, Option<&str>) { let mut ret = w; for delim in ['(', '{', '['] { |