diff --git a/src/lib.rs b/src/lib.rs
index 2ba555b..61a82af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -441,22 +441,45 @@ fn apply_furigana<'a>(
if pitches[0] == 0 {
// 平板.
let (s, k) = out.last_mut().unwrap();
+ let mark = if k.is_empty() {
+ // If we're putting this on a non-furigana character, add an
+ // extra level of furigana to make the formatting consistent.
+ &[
+ "",
+ "",
+ ]
+ } else {
+ &["", "o"]
+ };
let text = if k.is_empty() { s } else { k };
+
if text.len() >= 3 && text.is_char_boundary(text.len() - 3) {
- text.insert_str(text.len() - 3, "");
- text.insert_str(text.len(), "");
+ text.insert_str(text.len() - 3, mark[0]);
+ text.insert_str(text.len(), mark[1]);
}
} else {
// Everything else.
let mut byte_idx = accent::accent_number_to_byte_idx(kana, pitches[0]).unwrap();
for (s, k) in out.iter_mut() {
+ let mark = if k.is_empty() {
+ // If we're putting this on a non-furigana character, add an
+ // extra level of furigana to make the formatting consistent.
+ &[
+ "",
+ " *",
+ ]
+ } else {
+ &["", "*"]
+ };
let text = if k.is_empty() { s } else { k };
+
if byte_idx < text.len()
&& text.is_char_boundary(byte_idx)
&& text.is_char_boundary(byte_idx + 3)
{
- text.insert_str(byte_idx + 3, "");
- text.insert_str(byte_idx, "");
+ text.insert_str(byte_idx + 3, mark[1]);
+ text.insert_str(byte_idx, mark[0]);
+ break;
}
byte_idx -= text.len();
}
@@ -744,7 +767,7 @@ mod tests {
);
assert_eq!(
furi_2,
- r#"食タべるのは良いね!"#
+ r#"食タべ *るのは良いね!"#
);
}
@@ -792,7 +815,7 @@ mod tests {
// Ichidan verb. Should only get pitch accent marking in full dictionary form.
assert_eq!(
gen.add_html_furigana("食べる"),
- r#"食タべる"#
+ r#"食タべ *る"#
);
assert_eq!(
gen.add_html_furigana("食べます"),
@@ -806,7 +829,7 @@ mod tests {
// Godan verb. Should only get pitch accent marking in full dictionary form.
assert_eq!(
gen.add_html_furigana("泳ぐ"),
- r#"泳オヨぐ"#
+ r#"泳オヨ*ぐ"#
);
assert_eq!(
gen.add_html_furigana("泳が"),
@@ -818,13 +841,13 @@ mod tests {
);
assert_eq!(
gen.add_html_furigana("泳ぎ"),
- r#"泳オヨぎ"#
+ r#"泳オヨぎ *"#
);
// I-adjective. Should only get pitch accent marking in full dictionary form.
assert_eq!(
gen.add_html_furigana("早い"),
- r#"早ハヤい"#
+ r#"早ハヤ*い"#
);
assert_eq!(
gen.add_html_furigana("早く"),
@@ -834,19 +857,23 @@ mod tests {
// Other. Should always get pitch accent markings.
assert_eq!(
gen.add_html_furigana("少し"),
- r#"少スコし"#
+ r#"少スコ*し"#
);
assert_eq!(
gen.add_html_furigana("綺麗"),
- r#"綺麗キレイ"#
+ r#"綺麗キ*レイ"#
);
assert_eq!(
gen.add_html_furigana("平板"),
- r#"平板ヘイバン"#
+ r#"平板ヘイバンo"#
);
assert_eq!(
gen.add_html_furigana("他"),
- r#"他ホカ"#
+ r#"他ホカo"#
+ );
+ assert_eq!(
+ gen.add_html_furigana("中"),
+ r#"中ナ*カ"#
);
}
}