From 17595658f94ddf75d12bfcbb9e44a1ea0b2755b7 Mon Sep 17 00:00:00 2001 From: niksedk Date: Thu, 23 Sep 2021 18:38:27 +0200 Subject: [PATCH] More pac/italic - thx Milenko :) --- src/libse/SubtitleFormats/Pac.cs | 33 ++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/libse/SubtitleFormats/Pac.cs b/src/libse/SubtitleFormats/Pac.cs index 8153359c5..959d77a5e 100644 --- a/src/libse/SubtitleFormats/Pac.cs +++ b/src/libse/SubtitleFormats/Pac.cs @@ -1192,18 +1192,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats text = text.Replace("", ""); text = text.Replace("", ""); - - if (Utilities.CountTagInText(text, "") == 1 && text.StartsWith("", StringComparison.Ordinal) && text.EndsWith("", StringComparison.Ordinal)) - { - return "<" + HtmlUtil.RemoveHtmlTags(text).Replace(Environment.NewLine, Environment.NewLine + "<"); - } - var sb = new StringBuilder(); var parts = text.SplitToLines(); + var nextPre = string.Empty; foreach (string line in parts) { - string s = line.Trim(); - if (Utilities.CountTagInText(s, "") == 1 && s.StartsWith("", StringComparison.Ordinal) && s.EndsWith("", StringComparison.Ordinal)) + string s = nextPre + line.Trim(); + nextPre = string.Empty; + var noOfStartTags = Utilities.CountTagInText(s, ""); + var noOfEndTags = Utilities.CountTagInText(s, ""); + if (noOfStartTags == 1 && noOfEndTags ==1 && s.StartsWith("", StringComparison.Ordinal) && s.EndsWith("", StringComparison.Ordinal)) { sb.AppendLine("<" + HtmlUtil.RemoveHtmlTags(s)); } @@ -1214,6 +1212,11 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats s = s.Replace("___@___", ">"); s = s.Replace(" <", "<"); s = s.Replace("> ", ">"); + if (noOfStartTags > noOfEndTags) + { + s = s.TrimEnd() + ">"; + nextPre = ""; + } sb.AppendLine(s); } } @@ -1726,8 +1729,18 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats } } } - text = text.Replace(" ", " "); - return pre + text.Replace(" " + Environment.NewLine, Environment.NewLine).Trim(); + + text = text + .Replace(" ", " ") + .Replace(" ", " ") + .Replace(" " + Environment.NewLine, Environment.NewLine) + .Replace(" " + Environment.NewLine, Environment.NewLine) + .Replace(Environment.NewLine + " ", Environment.NewLine) + .Replace(Environment.NewLine + " ", Environment.NewLine) + .Replace("" + Environment.NewLine + "", Environment.NewLine) + .Trim(); + + return pre + HtmlUtil.FixInvalidItalicTags(text); } public static Encoding GetEncoding(int codePage)