Improve fix invalid italics tags - thx uckthis :)

Fix #4794
This commit is contained in:
Nikolaj Olsson 2021-02-12 16:05:35 +01:00
parent daf2843ded
commit df955a1e62

View File

@ -625,8 +625,11 @@ namespace Nikse.SubtitleEdit.Core.Common
int italicBeginTagCount = Utilities.CountTagInText(text, beginTag);
int italicEndTagCount = Utilities.CountTagInText(text, endTag);
int noOfLines = Utilities.GetNumberOfLines(text);
if (italicBeginTagCount + italicEndTagCount > 0)
if (italicBeginTagCount + italicEndTagCount == 0)
{
return preTags + text;
}
if (italicBeginTagCount == 1 && italicEndTagCount == 1 && text.IndexOf(beginTag, StringComparison.Ordinal) > text.IndexOf(endTag, StringComparison.Ordinal))
{
const string pattern = "___________@";
@ -763,7 +766,7 @@ namespace Nikse.SubtitleEdit.Core.Common
text = beginTag + text + endTag;
}
if (italicBeginTagCount == 0 && italicEndTagCount == 2 && text.StartsWith(endTag, StringComparison.Ordinal) && text.EndsWith(endTag, StringComparison.Ordinal))
if (italicBeginTagCount == 0 && italicEndTagCount == 2)
{
int firstIndex = text.IndexOf(endTag, StringComparison.Ordinal);
text = text.Remove(firstIndex, endTag.Length).Insert(firstIndex, beginTag);
@ -876,7 +879,7 @@ namespace Nikse.SubtitleEdit.Core.Common
text = text.Replace("<i></i>", string.Empty);
text = text.Replace("<i> </i>", string.Empty);
text = text.Replace("<i> </i>", string.Empty);
}
return preTags + text;
}