replace_invalid_lines() deletes rich text
Closed this issue · 0 comments
mrlogick commented
I have this main.rs
:
fn main() {
rsubs_lib::vtt::parse_from_file("./subs.vtt".to_string())
.unwrap()
.to_ass()
.to_file("./subs.ass")
.unwrap();
}
and this subs.vtt
:
WEBVTT
00:37.138 --> 00:38.990
<i>New Yorkers, a season high,
seven inches of rain last night.</i>
00:39.090 --> 00:42.076
<i>It looks like the storm has passed.</i>
I do cargo run
, and i get this subs.ass
:
[Script Info]
ScriptType: V4.00+
Synch Point:
WrapStyle: 0
PlayResY: 480
Title: subtitle
ScaledBorderAndShadows: yes
Script Updated By: rsubs lib
PlayResX: 640
Collisions: Normal
[V4+ Styles]
Format: Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,OutlineColour,BackColour,Bold,Italic,Underline,Strikeout,ScaleX,ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,MarginL,MarginR,MarginV,Encoding
Style: Default,Trebuchet MS,20,&H00FFFFFF,&H00000000,&H00000000,&H00000000,0,-1,-1,-1,120,120,0,0,1,1,1,2,0000,0000,0030,0
[Events]
Format: Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text
Dialogue: 0,0:00:37.13,0:00:38.99,Default,,0000,0000,0000,,New Yorkers, a season high,
seven inches of rain last night.
Dialogue: 0,0:00:39.09,0:00:42.07,Default,,0000,0000,0000,,It looks like the storm has passed.
As you can see, the .ass file is losing rich-text informaion. <i>
and </i>
are being replaced with empty strings. (I think this happens inside replace_invalid_lines()
in vtt.rs
)
I'm my opinion we should replace <i>text</i>
(that is found very often in .srt or .vtt files) with {\i1}text{\i0}
(supported by .ass files)
We should write conversions somewhere, something like this:
line_text = str::replace(&line_text, "<i>", "{\\i1}");
line_text = str::replace(&line_text, "</i>", "{\\i0}");
line_text = str::replace(&line_text, "<b>", "{\\b1}");
line_text = str::replace(&line_text, "</b>", "{\\b0}");
line_text = str::replace(&line_text, "<u>", "{\\u1}");
line_text = str::replace(&line_text, "</u>", "{\\u0}");
line_text = str::replace(&line_text, "<s>", "{\\s1}");
line_text = str::replace(&line_text, "</s>", "{\\s0}");