fix(captions): preserve whitespace-tolerant styling tags

This commit is contained in:
Nigel Ihza Firdausy 2026-10-10 23:57:43 +07:00
parent f9f0268b65
commit fc69e9cad9
1 changed files with 2 additions and 2 deletions

View File

@ -219,8 +219,7 @@ fn encode_text(text: &str) -> Vec<u8> {
// Only a syntactically plausible tag is markup. Comparisons such as
// "2 < 3 > 1" and "x < y > z" must not lose their middle text.
let name = tag.strip_prefix('/').unwrap_or(tag);
let is_tag = name.as_bytes().first().is_some_and(u8::is_ascii_alphabetic)
&& tag.trim() == tag;
let is_tag = name.as_bytes().first().is_some_and(u8::is_ascii_alphabetic);
if is_tag {
match tag.to_ascii_lowercase().as_str() {
"i" => out.push(0x80),
@ -477,6 +476,7 @@ mod tests {
assert_eq!(decoded.cues[0].text, literal);
// Recognized styling still becomes STL control bytes.
assert_eq!(encode_text("<i>Hi</i>"), vec![0x80, b'H', b'i', 0x81]);
assert_eq!(encode_text("<i >Hi</i >"), vec![0x80, b'H', b'i', 0x81]);
}
#[test]