aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs54
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>&nbsp;&nbsp;<span style="font-size: 1.2em">{}</span>&nbsp;&nbsp;</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 ['(', '{', '['] {