mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 11:12:36 +01:00
Fix "Fix invalid italic tags" with ASS tags - thx Jamakmake :)
This commit is contained in:
parent
5741e1ab89
commit
34a63df46a
@ -543,6 +543,17 @@ namespace Nikse.SubtitleEdit.Core
|
||||
{
|
||||
var text = input;
|
||||
|
||||
var preTags = string.Empty;
|
||||
if (text.StartsWith("{\\", StringComparison.Ordinal))
|
||||
{
|
||||
var endIdx = text.IndexOf('}', 2);
|
||||
if (endIdx > 2)
|
||||
{
|
||||
preTags = text.Substring(0, endIdx + 1);
|
||||
text = text.Remove(0, endIdx + 1);
|
||||
}
|
||||
}
|
||||
|
||||
const string beginTag = "<i>";
|
||||
const string endTag = "</i>";
|
||||
|
||||
@ -846,7 +857,7 @@ namespace Nikse.SubtitleEdit.Core
|
||||
text = text.Replace("<i> </i>", string.Empty);
|
||||
text = text.Replace("<i> </i>", string.Empty);
|
||||
}
|
||||
return text;
|
||||
return preTags + text;
|
||||
}
|
||||
|
||||
public static string ToggleTag(string input, string tag)
|
||||
|
@ -1208,12 +1208,23 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
/// <summary>
|
||||
/// Fix italic tags, lines starting with ">" - whole line is italic, words between <> is italic
|
||||
/// </summary>
|
||||
private static string FixItalics(string text)
|
||||
private static string FixItalics(string input)
|
||||
{
|
||||
var pre = string.Empty;
|
||||
var text = input;
|
||||
if (text.StartsWith("{\\", StringComparison.Ordinal))
|
||||
{
|
||||
var endIdx = text.IndexOf('}', 2);
|
||||
if (endIdx > 2)
|
||||
{
|
||||
pre = text.Substring(0, endIdx + 1);
|
||||
text = text.Remove(0, endIdx + 1);
|
||||
}
|
||||
}
|
||||
int index = text.IndexOf('<');
|
||||
if (index < 0)
|
||||
{
|
||||
return text;
|
||||
return input;
|
||||
}
|
||||
|
||||
while (index >= 0 && index < text.Length - 1)
|
||||
@ -1242,7 +1253,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
|
||||
}
|
||||
text = text.Replace("</i>", "</i> ");
|
||||
text = text.Replace(" ", " ");
|
||||
return text.Replace(" " + Environment.NewLine, Environment.NewLine).Trim();
|
||||
return pre + text.Replace(" " + Environment.NewLine, Environment.NewLine).Trim();
|
||||
}
|
||||
|
||||
public static Encoding GetEncoding(int codePage)
|
||||
|
@ -429,6 +429,14 @@ namespace Test.Logic
|
||||
Assert.AreEqual(s2, "<i>Hallo!" + Environment.NewLine + "Hallo!" + Environment.NewLine + "Hallo!</i>");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FixInvalidItalicTagsWithAssTag()
|
||||
{
|
||||
var s1 = "{\\an8}<i>Hallo!<i/>" + Environment.NewLine + "<i>Hallo!<i/>";
|
||||
string s2 = HtmlUtil.FixInvalidItalicTags(s1);
|
||||
Assert.AreEqual(s2, "{\\an8}<i>Hallo!" + Environment.NewLine + "Hallo!</i>");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FixUnneededSpacesDoubleSpace1()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user