Parse SubRip line by line so empty lines are not dropped - #293
Merged
Merged
Conversation
Subtitle Edit writes a paragraph with no text as "N / time / blank / blank". SubRipParser.Parse split on blank lines and skipped blocks under 3 lines, so the empty paragraph was dropped along with the paragraph after it (its time line landed at lines[2]). Plugins that parse and serialize the whole subtitle deleted those lines, and every SelectedIndices entry below them was shifted. Parse is now a line-based reader: a block starts at a number followed by a time code line (at the start or after a blank line), text accumulates until the next block start, and trailing blank lines are trimmed. The time code pattern also accepts hours past 99 and negative times, both of which SE writes and the old pattern dropped. The public API is unchanged. TypewriterEffect's copy of the parser gets the same fix. Haxor had its own blank-line split: a line whose text contained a blank line split in two and shifted the selection, so it now walks lines the same way. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problem
Subtitle Edit 5 writes a paragraph with no text as
N / time / blank / blank(SubRip.ToText).SubRipParser.Parsesplit the SRT on blank lines and skipped blocks with fewer than 3 lines, so:lines[2]instead oflines[1], and it was dropped too.Plugins that parse and serialize the whole subtitle (RemoveUnicodeCharacters, WordCensor, AmericanToBritish, BritishToAmerican, TypewriterEffect) therefore deleted lines from the user's subtitle, and every
SelectedIndicesentry below the empty line was shifted. Example:["Hello.", "", "- Andro!\n- Ben, I've been oozed.", "Last."]parsed to 2 blocks.Fix
se5/Plugin-Shared/SubRipParser.cs:Parseis now line based. A block starts at a number line followed by a time code line (at the start or after a blank line); text lines accumulate until the next block start; trailing blank lines are trimmed. The time code pattern also accepts hours past 99 and a leading-for negative times, both of which SE writes and the old pattern dropped. Public API (SrtBlock,Parse,Serialize) is unchanged.se5/TypewriterEffect/SubRipParser.cs: same fix in TypewriterEffect's own copy.se5/Haxor/Program.cs: Haxor had its own blank-line split. Empty lines lined up by accident, but a line whose text contains a blank line split in two: selecting the line after it changed nothing, and selecting the line itself translated only its first half. It now walks the lines the same way; output is otherwise unchanged.Verification
A scratch test project referencing SE's libse (
SubRip.ToText/LoadSubtitle), run with CRLF and LF:Serialize(Parse(srt))is byte identical to SE's output, and editing index 2 changes only the dialog.Serializestill writes negative times as 0, as before.After merge
Each affected plugin needs a release (workflow dispatch with
release), thense5-plugins.jsonpointed at the new releases:american-to-british.yml,british-to-american.yml,remove-unicode-characters.yml,word-censor.yml(Plugin-Shared)typewriter.yml,haxor.yml(own changes)SrtCueDocumentonclaude/split-dialogscould then useSubRipParser.Parseinstead of its own reader.🤖 Generated with Claude Code