Allow multiple blank lines in .srt files - thx Sopor- :)

This commit is contained in:
Nikolaj Olsson 2019-02-23 21:52:57 +01:00
parent ad3a391689
commit 13148b5742
2 changed files with 53 additions and 3 deletions

View File

@ -98,7 +98,13 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
if (_expecting == ExpectingLine.Text && i + 1 < lines.Count && !string.IsNullOrEmpty(_paragraph?.Text) &&
(Utilities.IsInteger(line) && RegexTimeCodes.IsMatch(next.Trim()) || RegexTimeCodes.IsMatch(line.Trim())))
{
ReadLine(subtitle, string.Empty, string.Empty, string.Empty, string.Empty);
if (!string.IsNullOrEmpty(_paragraph.Text))
{
subtitle.Paragraphs.Add(_paragraph);
_lastParagraph = _paragraph;
_paragraph = new Paragraph();
}
_expecting = ExpectingLine.Number;
}
if (_expecting == ExpectingLine.Number && RegexTimeCodes.IsMatch(line.Trim()))
{
@ -126,7 +132,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
p.EndTime.Milliseconds = FramesToMillisecondsMax999(p.EndTime.Milliseconds);
}
}
foreach (Paragraph p in subtitle.Paragraphs)
{
p.Text = p.Text.TrimEnd();
}
Errors = _errors.ToString();
}
@ -204,6 +213,10 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
_expecting = ExpectingLine.Number;
}
}
else if (string.IsNullOrEmpty(line) && string.IsNullOrEmpty(next))
{
_paragraph.Text += Environment.NewLine + RemoveBadChars(line).TrimEnd();
}
else
{
subtitle.Paragraphs.Add(_paragraph);

View File

@ -257,7 +257,44 @@ ppp
}
[TestMethod]
public void SrtDifficultLines3()
{
var target = new SubRip();
var subtitle = new Subtitle();
const string text = @"1
00:06:25,218 --> 00:06:27,420
<font color='white' face='monospace' size='1c'>
We have detected a new signal.
</font>
2
00:06:32,225 --> 00:06:34,526
<font color='white' face='monospace' size='1c'>
Where is it this time?
</font>
3
00:06:34,560 --> 00:06:37,096
<font color='white' face='monospace' size='1c'>
Outside of Federation space.
</font>";
target.LoadSubtitle(subtitle, GetSrtLines(text), null);
Assert.AreEqual(3, subtitle.Paragraphs.Count);
Assert.AreEqual(@"<font color='white' face='monospace' size='1c'>
We have detected a new signal.
</font>", subtitle.Paragraphs[0].Text); Assert.AreEqual(@"<font color='white' face='monospace' size='1c'>
Where is it this time?
</font>", subtitle.Paragraphs[1].Text);
}
#endregion SubRip (.srt)