From 96141ae3c55ea5a7b0a923aa58c8a035e1f6f893 Mon Sep 17 00:00:00 2001
From: wei <104672881+shengzhaowei@users.noreply.github.com>
Date: Sun, 22 Nov 2026 16:41:31 +0800
Subject: [PATCH] fix(docx): keep base text of phonetic guides (w:ruby)
---
src/formats/docx/content.rs | 12 ++++++++++++
src/formats/docx/mod.rs | 19 +++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/src/formats/docx/content.rs b/src/formats/docx/content.rs
index c5a7c18b..e134e1b3 100644
--- a/src/formats/docx/content.rs
+++ b/src/formats/docx/content.rs
@@ -538,6 +538,18 @@ impl<'a, 'b, 'e> InlineWalker<'a, 'b, 'e> {
f.instr.push_str(&child.text());
}
}
+ "ruby" => {
+ // Phonetic guide: keep the base text (w:rubyBase) and
+ // drop the pronunciation (w:rt) and properties
+ // (w:rubyPr), matching the xlsx rPh handling.
+ if let Some(base) = child.find(ns::W, "rubyBase") {
+ for run in base.child_elems() {
+ if run.is(ns::W, "r") {
+ self.walk_run(run)?;
+ }
+ }
+ }
+ }
_ => {}
}
}
diff --git a/src/formats/docx/mod.rs b/src/formats/docx/mod.rs
index eee5317e..cc2dc5cb 100644
--- a/src/formats/docx/mod.rs
+++ b/src/formats/docx/mod.rs
@@ -287,6 +287,25 @@ mod tests {
}
}
+ #[test]
+ fn ruby_phonetic_guide_keeps_its_base_text() {
+ // A w:ruby keeps its base text and drops the pronunciation (w:rt);
+ // without a ruby branch the whole guide was silently discarded.
+ let body = r#"
+ Before
+
+
+ tō
+ 東
+
+ after
+ "#;
+ let document = format!(r#"{body}"#);
+ let bytes = docx_parts(&[("word/document.xml", &document)]);
+ let markdown = crate::to_markdown_bytes(&bytes, crate::Format::Docx).unwrap();
+ assert_eq!(markdown, "Before 東 after\n");
+ }
+
#[test]
fn numbered_heading_keeps_its_number() {
// H1: a heading style with numbering shows its label and advances