mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-09-12 05:16:19 -07:00
fix(subtitles): keep overlapping lines that join an already active cue (#221)
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
getFrequencyRankLabelForToken,
|
||||
getJlptLevelLabelForToken,
|
||||
normalizeSubtitle,
|
||||
normalizeSubtitleForDisplay,
|
||||
prepareSecondarySubtitleLines,
|
||||
sanitizeSubtitleHoverTokenColor,
|
||||
shouldRenderTokenizedSubtitle,
|
||||
@@ -1004,6 +1005,34 @@ test('normalizeSubtitle collapses explicit line breaks when collapseLineBreaks i
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeSubtitleForDisplay always breaks between simultaneous cues', () => {
|
||||
// The blank line marks two distinct cues on screen at once. Flattening it would run a
|
||||
// sign or a second speaker into the line beside it as one sentence.
|
||||
const twoCues =
|
||||
'\u6b21\u306f\u9b3c\u5b50\u6bcd\u795e\u524d\u3000\u9b3c\u5b50\u6bcd\u795e\u524d\n\n\u611b\u97f3\u3061\u3083\u3093\u3000\u3082\u3046\u5199\u771f\u4e0a\u3052\u3066\u308b';
|
||||
|
||||
assert.equal(
|
||||
normalizeSubtitleForDisplay(twoCues, false),
|
||||
'\u6b21\u306f\u9b3c\u5b50\u6bcd\u795e\u524d \u9b3c\u5b50\u6bcd\u795e\u524d\n\u611b\u97f3\u3061\u3083\u3093 \u3082\u3046\u5199\u771f\u4e0a\u3052\u3066\u308b',
|
||||
);
|
||||
assert.equal(normalizeSubtitleForDisplay(twoCues, true), twoCues.replace('\n\n', '\n'));
|
||||
});
|
||||
|
||||
test('normalizeSubtitleForDisplay preserves CRLF boundaries between simultaneous cues', () => {
|
||||
assert.equal(normalizeSubtitleForDisplay('a\r\n\r\nb', false), 'a\nb');
|
||||
});
|
||||
|
||||
test('normalizeSubtitleForDisplay still flattens a wrap inside one cue', () => {
|
||||
// A typesetter's \\N inside a single utterance is what preserveLineBreaks governs.
|
||||
assert.equal(
|
||||
normalizeSubtitleForDisplay(
|
||||
'\u5e38\u4eba\u304c\u4f7f\u3048\u3070\\N\u305d\u306e\u5727\u5012\u7684\u306a\u529b\u306b',
|
||||
false,
|
||||
),
|
||||
'\u5e38\u4eba\u304c\u4f7f\u3048\u3070 \u305d\u306e\u5727\u5012\u7684\u306a\u529b\u306b',
|
||||
);
|
||||
});
|
||||
|
||||
test('normalizeSubtitle leaves already-decoded text alone', () => {
|
||||
// Primary subtitle text is decoded from ASS once, upstream: by mpv for live lines and
|
||||
// by the cue parser for prefetched ones. A brace that survives that is literal text.
|
||||
|
||||
Reference in New Issue
Block a user