diff options
-rw-r--r-- | src/main.rs | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index d877fce..70a7fa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1213,10 +1213,32 @@ fn format_batch_aux<'a>( r#"<details><summary>Extra examples (reading practice)</summary><table class="extratable">"# )?; for ex in batch.extra_examples.iter() { + let mut expl1 = Vec::new(); + let mut expl2 = Vec::new(); + for word in ex.expl.split(|c| c == ' ' || c == '~') { + let (keb, reb) = expl_clean_word(word); + let wchars = Charset::new(keb); + if !wchars.intersects(&ex.chars) { + continue; + } + if let Some(ents) = dict_idx.get(keb) { + for ent in ents.iter() { + if let Some(s) = dict_str_short(keb, reb, ent) { + if wchars.intersects(&batch.chars) { + expl1.push(s); + } else { + expl2.push(s); + } + } + } + } + } + expl1.extend(expl2.into_iter()); + let expl = expl1.join("<br />"); writeln!( f, - r#"<tr><td><details><summary class="tab_large font_ja"> {} </summary><div style="text-align: center">{}</div></details></td></tr>"#, - ex.ja, ex.en + r#"<tr><td><details><summary class="tab_large font_ja"> {} </summary><div style="text-align: center">{}<br />{}</div></details></td></tr>"#, + ex.ja, ex.en, expl )?; } writeln!(f, r#"</table></details>"#)?; @@ -1262,7 +1284,11 @@ fn expl_clean_word(w: &str) -> (&str, Option<&str>) { (ret, p) } -fn dict_str<'a>(qkeb: &str, qreb: Option<&str>, ent: &roxmltree::Node<'a, 'a>) -> Option<String> { +fn dict_str_short<'a>( + qkeb: &str, + qreb: Option<&str>, + ent: &roxmltree::Node<'a, 'a>, +) -> Option<String> { let r_ele = ent.children().find(|x| x.has_tag_name("r_ele")).unwrap(); let reb = r_ele.children().find(|x| x.has_tag_name("reb")).unwrap(); let reb = reb.text().unwrap().trim(); @@ -1271,7 +1297,14 @@ fn dict_str<'a>(qkeb: &str, qreb: Option<&str>, ent: &roxmltree::Node<'a, 'a>) - return None; } - let mut ret = format!(r#"<span class="font_ja">{} 【{}】</span>"#, qkeb, reb); + Some(format!( + r#"<span class="font_ja">{} 【{}】</span>"#, + qkeb, reb + )) +} + +fn dict_str<'a>(qkeb: &str, qreb: Option<&str>, ent: &roxmltree::Node<'a, 'a>) -> Option<String> { + let mut ret = dict_str_short(qkeb, qreb, ent)?; for sense in ent.children().filter(|x| x.has_tag_name("sense")) { if let Some(s) = sense.children().find(|x| x.has_tag_name("gloss")) { |