Repository navigation
fix(docx): keep base text of phonetic guides (w:ruby) - #236
Open
shengzhaowei wants to merge 1 commit into
Open
shengzhaowei wants to merge 1 commit into
shengzhaowei wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 3/5
content.rsdrops base text when valid<w:ins>or other wrapper elements sit betweenrubyBaseand its runs. WalkrubyBasewith the regular inline walker so wrapped text is preserved.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/formats/docx/content.rs">
<violation number="1" location="src/formats/docx/content.rs:546">
P2: This drops base text wrapped in valid elements such as `<w:ins>`, because the loop only processes direct `<w:r>` children. Walk `rubyBase` through the regular inline walker so wrapped base runs are preserved.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.
View guided diff | Re-trigger cubic
Comment on lines
+546
to
+550
| for run in base.child_elems() { | ||
| if run.is(ns::W, "r") { | ||
| self.walk_run(run)?; | ||
| } | ||
| } |
There was a problem hiding this comment.
P2: This drops base text wrapped in valid elements such as <w:ins>, because the loop only processes direct <w:r> children. Walk rubyBase through the regular inline walker so wrapped base runs are preserved.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/formats/docx/content.rs, line 546:
<comment>This drops base text wrapped in valid elements such as `<w:ins>`, because the loop only processes direct `<w:r>` children. Walk `rubyBase` through the regular inline walker so wrapped base runs are preserved.</comment>
<file context>
@@ -538,6 +538,18 @@ impl<'a, 'b, 'e> InlineWalker<'a, 'b, 'e> {
+ // 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)?;
</file context>
Suggested change
| for run in base.child_elems() { | |
| if run.is(ns::W, "r") { | |
| self.walk_run(run)?; | |
| } | |
| } | |
| self.walk(base)?; |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix/docx-ruby-base-text(head96141ae)main(6feb6c2)w:ruby) base text is silently dropped #235Diffstat
Problem
walk_run_content()had no"ruby"arm, so aw:rubyfell through to the catch-all_ => {}and its base text was silently dropped:Before 東 after(guidetō) rendered asBefore after. This loses content characters, not decoration, in a feature common in CJK documents.Fix
Add a
"ruby"arm: walk intow:rubyBaseand render its runs with the existingwalk_run(), skipping the pronunciation (w:rt) and properties (w:rubyPr). This matches the XLSX side'srPhhandling. Per the specw:rubyonly appears insidew:r, so no paragraph-level branch is needed, and ruby inside hyperlinks/text boxes goes through the samewalk_run_contentpath. No API, model, or renderer change.Tests
ruby_phonetic_guide_keeps_its_base_text(insrc/formats/docx/mod.rs).cargo run --example convert -- handmade-ruby.docxoutputsBefore after; after:Before 東 after. (Note: anydoc has no executable binary; the convert example is the entry point.)git stash) and passes after. Fullcargo test --release: lib 287 passed; other suites 2 + 1 + 10 (9 passed, 1 ignored, 0 failed).cargo fmt --checkis clean.Summary by cubic
Fixes DOCX phonetic guides (
w:ruby) so their base text is no longer dropped when converting to Markdown. PreviouslyBefore 東 after(with guidetō) rendered asBefore after, losing content characters common in CJK documents. Closes #235."ruby"arm that renders the base text runs and skips pronunciation and properties, matching the existing XLSXrPhhandling.Written for commit 96141ae. Summary will update on new commits.