Repository navigation
Conversation
Both writers added a separator space after text nodes and closing tags even when the neighbouring text node already carried its own whitespace, so a styled word gained one more space on every conversion. The separator is now deferred and only written when neither side has whitespace at that position. Nodes without whitespace of their own get the same output as before. Fixes pbs#467
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Description
Fixes #467
A caption with an inline-styled word picked up an extra space around the styled span each time it went through
SAMIWriterorDFXPWriter, soHello <b>world</b> endbecameHello <b>world</b> end, then three spaces on the next round trip, and so on.Both writers add a separator space of their own:
SAMIWriterafter every text node and after a closing tag,DFXPWriterafter a closing</span>. That's needed when the nodes carry no whitespace (Hello,world,end), but text nodes read from WebVTT, SAMI or DFXP already keep the whitespace they had ('Hello ',' end'), so the separator landed on top of it.The separator is now only written when neither side already has whitespace there. Instead of appending
" "straight away, the writers remember that one is owed and add it when the next piece of the line is written, if it's still needed. The rest of the output is unchanged: unspaced nodes still get their separator, and trailing whitespace before a closing tag or a<br/>is still stripped.One fixture changes.
sample_sami_from_dfxp_with_nested_spansexpectedThat is <span ...>with two spaces, where the DFXP it's converted from has one, so it had the bug baked in.Not changed here: a closing tag followed directly by punctuation still gets a separator (
nested</span></span></span>.in DFXP comes out as...</span> .in SAMI). That's the existing behaviour for unspaced nodes and a different question from the doubling, so I left it alone.Testing
New
TestInlineStyleSpacingintests/test_webvtt_conversion.py:test_sami_writer_does_not_double_spacesandtest_dfxp_writer_does_not_double_spaces: the cue from the issue, written oncetest_spacing_is_stable_across_round_trips: three WebVTT -> SAMI/DFXP -> WebVTT round trips, for both formatstest_separator_is_still_added_between_unspaced_nodes: nodes without their own whitespace get the same output as beforeThe first four cases fail on
mainand pass here. The last two pass on both, they're there to pin the behaviour that shouldn't move.Full suite on Python 3.12 with lxml 5.4:
1428 passed(1422 passedonmain, the difference is the new tests).ruff checkandruff format --checkare clean on the touched files.One thing I ran into that isn't related to this PR: with lxml 6.2 installed, 40 tests fail on
mainas well as on this branch (mostlyKeyError: 'tts:origin'in the DFXP tests).test_requirements.txthaslxml>=4.9.1with no upper bound, so a fresh install picks 6.2. I can open a separate issue for it if that's useful.Checklist