Skip to content

fix(webvtt): parse cue ruby spans instead of dropping their cues - #935

Merged
ceberam merged 3 commits into
docling-project:mainfrom
Krushil-Dhankecha:fix/webvtt-ruby-spans
Nov 13, 2026
Merged

ceberam merged 3 commits into
docling-project:mainfrom
Krushil-Dhankecha:fix/webvtt-ruby-spans

Conversation

@Krushil-Dhankecha

@Krushil-Dhankecha Krushil-Dhankecha commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #934.

A cue with a <ruby> annotation failed to parse and was dropped from the file with only a RuntimeWarning: the unknown-tag pass kept ruby and rt tags 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) and WebVTTCueRubyTextSpan (rt) join the component union, the tag pattern, and _create_span; the special case for them in _strip_unknown_tag goes away. Both classes are exported from docling_core.types.doc.
  • START_TAG_NAMES is the single list of cue tag names: it types the cue component kind and builds the tag pattern, so adding a tag no longer requires keeping several copies in sync.
  • The end tag of the last ruby text span may be omitted, so </ruby> implicitly closes an open <rt> (WebVTT 1, 4.2.2), factored into a small _close_top_span helper that also closes the spans left open at the end of the cue. Serialization always writes </rt> out, so str() returns well-formed cue text.
  • Following the cue text parsing rules (WebVTT 1, 6.4), an <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.
  • Mismatched end tags are still rejected (for example <ruby>a<rt>b<i>c</ruby>), as documented in the WebVTTCueBlock docstring, and a stray end tag with no open span is still ignored, as before.

Tests in tests/test_webvtt.py:

  • test_webvtt_ruby_spans is 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_ignored and test_webvtt_ruby_text_outside_ruby_is_ignored cover the <rt> rules from section 6.4.
  • test_webvtt_file_ruby_spans_example parses the new tests/data/webvtt/webvtt_example_05.vtt under warnings.simplefilter("error") and keeps all five cues, including a ruby span inside a voice span.

On main the ruby cue is missing from the parsed file (the repro in #934). The tests in tests/test_webvtt.py pass, and ruff format --check and ruff check are clean.

Downstream, docling's WebVTT backend walks any span through internal_text generically, so cues with ruby annotations now reach the DoclingDocument without further changes there.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @Krushil-Dhankecha, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working media Images, audio, video, WebVTT, PDF shapes/widgets, MIME types, ImageRef labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 3c7db45147. The analysis read the diff only. It did not run code from this pull request.

The PR adds WebVTT cue ruby spans, WebVTTCueRubySpan and WebVTTCueRubyTextSpan, to the cue parser. Cues with <ruby> and <rt> tags now parse instead of being dropped. The parser also closes an <rt> span whose end tag is missing.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#972 open changes the same code related: Both PRs change WebVTT code and add tests to tests/test_webvtt.py. PR 972 escapes text and voice names in export_to_vtt. This PR adds ruby parsing. The two changes do not conflict.

Reference data changes

Change Files
added 1
  • added tests/data/webvtt/webvtt_example_05.vtt

Assessment: expected. The PR adds tests/data/webvtt/webvtt_example_05.vtt as new input for test_webvtt_file_ruby_spans_example. That test reads the file and checks five cues with ruby annotations. No existing reference data changes.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 3, 2026
@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Krushil-Dhankecha and others added 3 commits November 13, 2026 14:55
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>
@ceberam
ceberam force-pushed the fix/webvtt-ruby-spans branch from 54d81c4 to 3c7db45 Compare November 13, 2026 14:46
@github-actions github-actions Bot removed the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 13, 2026

@ceberam ceberam left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 WebVTTCueRubySpan and WebVTTCueRubyTextSpan from docling_core.types.doc, like the other cue components.
    • I added a file webvtt_example_05.vtt to better visualize the new cue spans and tests for this.
  • refactor(webvtt): derive cue tag names from START_TAG_NAMES: START_TAG_NAMES is now the only list of tag names. It types the cue component kind and 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!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working media Images, audio, video, WebVTT, PDF shapes/widgets, MIME types, ImageRef

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebVTT cue with a ruby annotation is dropped

3 participants