Repository navigation
fix(webvtt): parse cue ruby spans instead of dropping their cues - #935
Conversation
|
✅ DCO Check Passed Thanks @Krushil-Dhankecha, all your commits are properly signed off. 🎉 |
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
🟢 Require two reviewer for test updatesWhen test data is updated, we require two reviewers
|
AI triage (advisory)Checked commit The PR adds WebVTT cue ruby spans, CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
Reference data changes
Assessment: expected. The PR adds The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 54d81c431b. It read the code and did not run it.
I found no defect that must stop the merge. The change only touches docling_core/types/doc/webvtt.py. I traced the new <ruby>/<rt> parse path, including the implicit <rt> close, and found no regression to other tags or serializers. The WebVTTCueBlock.parse output for <ruby> and <rt> now matches the other span types, and docling_core/transforms/serializer/webvtt.py builds its spans separately.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
A cue holding a <ruby> annotation was dropped as a whole: the unknown-tag pass kept ruby and rt tags, the text-span validator then rejected the leftover "<", and WebVTTFile.parse lost the cue with only a RuntimeWarning (docling-project#934). Model the WebVTT cue ruby span and cue ruby text span (WebVTT 1, 4.2.2) as cue components. An open <rt> is closed implicitly by the next <rt> or by </ruby>, since the end tag of the last ruby text span may be omitted; serialization always writes it back out. Signed-off-by: krushil dhankecha <dhankechakrushil@gmail.com>
Follow the WebVTT cue text parsing rules (WebVTT 1, 6.4) for ruby text spans. An <rt> start tag only applies when the innermost open span is a <ruby>; otherwise it is ignored, and so is an </rt> end tag when no <rt> is open. As a result, an <rt> inside an open <rt> no longer closes it and starts a sibling (the text is kept in the open span), and an <rt> outside a <ruby> no longer produces a cue ruby text span. The implicit close of the last <rt> by </ruby> is unchanged, and the guard that protected it from an empty tag stack is no longer needed. Export WebVTTCueRubySpan and WebVTTCueRubyTextSpan from docling_core.types.doc, like the other cue components. Add webvtt_example_05.vtt, a file with ruby spans, and tests for it and for the <rt> handling above. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Use START_TAG_NAMES as the single list of cue span tag names. The cue component kind is typed with it and the cue tag pattern is built from its values, so adding a tag no longer requires keeping several copies in sync. In WebVTTCueBlock.parse, close spans through _close_top_span in the end-tag branch and in the final loop that closes the remaining open spans, and drop the membership check on the tag name, which always holds because the tag pattern only matches known tags. Behaviour is unchanged. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
54d81c4 to
3c7db45
Compare
There was a problem hiding this comment.
Hi @Krushil-Dhankecha, thanks for the PR and for the clear report in #934. I pushed two small commits on top of yours before merging:
fix(webvtt): follow the spec for <rt> tags and export ruby spans:- Section 6.4 of the spec says an
<rt>start tag only applies directly inside<ruby>, and an</rt>is ignored when no<rt>is open. Without this, a stray<rt>outside<ruby>produced a ruby text span, and an<rt>inside an open<rt>closed it and started a sibling. - I also exported
WebVTTCueRubySpanandWebVTTCueRubyTextSpanfromdocling_core.types.doc, like the other cue components. - I added a file
webvtt_example_05.vttto better visualize the new cue spans and tests for this.
- Section 6.4 of the spec says an
refactor(webvtt): derive cue tag names from START_TAG_NAMES:START_TAG_NAMESis now the only list of tag names. It types the cue componentkindand builds the tag regex, so adding a tag no longer means editing several copies. I also factored the repeated span-closing code into_close_top_span. Behavior is unchanged.- I slightly edited the PR description and changed only the parts that no longer match the code.
Your parsing and round-trip approach is untouched. Thanks again for the contribution!
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 3c7db45147. It read the code and did not run it.
Note
The history changed after the earlier AI review (a rebase or force-push), so the changes since then could not be compared. This review covers the full diff and checks the earlier findings again.
I found no defect that must stop the merge. I traced the new <ruby> and <rt> parse path in WebVTTCueBlock.parse and the new START_TAG_NAMES literal. They are consistent with _create_span, the tag pattern, the stray end-tag handling, and the WebVTT serializer. The serializer does not build ruby spans, so its output does not change. The PR description says the next <rt> closes an open <rt>, but the code ignores that nested start tag and merges its text into the open <rt>. The tests state this behaviour, and it follows WebVTT 1, 6.4.
A maintainer makes the merge decision. This review never approves the pull request.
Closes #934.
A cue with a
<ruby>annotation failed to parse and was dropped from the file with only aRuntimeWarning: the unknown-tag pass keptrubyandrttags as "not modeled yet", and the text-span validator then rejected the leftover<. Files using furigana lost those cues entirely, surrounding plain text included.This models the two spans from WebVTT 1, section 4.2.2, as cue components:
WebVTTCueRubySpan(ruby) andWebVTTCueRubyTextSpan(rt) join the component union, the tag pattern, and_create_span; the special case for them in_strip_unknown_taggoes away. Both classes are exported fromdocling_core.types.doc.START_TAG_NAMESis the single list of cue tag names: it types the cue componentkindand builds the tag pattern, so adding a tag no longer requires keeping several copies in sync.</ruby>implicitly closes an open<rt>(WebVTT 1, 4.2.2), factored into a small_close_top_spanhelper that also closes the spans left open at the end of the cue. Serialization always writes</rt>out, sostr()returns well-formed cue text.<rt>start tag only applies when the innermost open span is a<ruby>. Otherwise it is ignored and its text is kept in the open span, so<ruby>日<rt>に<rt>ほん</rt></ruby>is serialized as<ruby>日<rt>にほん</rt></ruby>. An<rt>outside a<ruby>and an</rt>with no open<rt>are ignored in the same way.<ruby>a<rt>b<i>c</ruby>), as documented in theWebVTTCueBlockdocstring, and a stray end tag with no open span is still ignored, as before.Tests in
tests/test_webvtt.py:test_webvtt_ruby_spansis parametrized over the explicit pair, the omitted final</rt>, and several base/annotation pairs in one span, each checking the parsed structure and the serialization.test_webvtt_ruby_text_start_tag_inside_ruby_text_is_ignoredandtest_webvtt_ruby_text_outside_ruby_is_ignoredcover the<rt>rules from section 6.4.test_webvtt_file_ruby_spans_exampleparses the newtests/data/webvtt/webvtt_example_05.vttunderwarnings.simplefilter("error")and keeps all five cues, including a ruby span inside a voice span.On
mainthe ruby cue is missing from the parsed file (the repro in #934). The tests intests/test_webvtt.pypass, andruff format --checkandruff checkare clean.Downstream, docling's WebVTT backend walks any span through
internal_textgenerically, so cues with ruby annotations now reach theDoclingDocumentwithout further changes there.