diff options
author | Alex Auvolat <alex@adnab.me> | 2023-10-06 14:30:48 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-10-06 14:30:57 +0200 |
commit | d602f00607aa23cf49485637fc88f0484746a80d (patch) | |
tree | b46378d040b830ea0b950f3e1046dd2a4b3694d8 /src/main.rs | |
parent | b6f598bb5ecafc9239b7140dd23596ddec168eab (diff) | |
download | datagengo-d602f00607aa23cf49485637fc88f0484746a80d.tar.gz datagengo-d602f00607aa23cf49485637fc88f0484746a80d.zip |
improve vocab table format
Diffstat (limited to 'src/main.rs')
-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 ['(', '{', '['] { |