diff --git a/Changelog.txt b/Changelog.txt
index 825fa2855..67d3b481c 100644
--- a/Changelog.txt
+++ b/Changelog.txt
@@ -15,6 +15,7 @@
* Update yt-dlp to 2023-11-16
* FIXED:
* Fix Whisper CPP cuBLAS new hash (DLL files now included)
+ * Fix minor space issue with "Fix italic tags" - thx Adam
4.0.2 (19th November 2023)
diff --git a/src/Test/Logic/UtilitiesTest.cs b/src/Test/Logic/UtilitiesTest.cs
index b5948d6c5..db0df471a 100644
--- a/src/Test/Logic/UtilitiesTest.cs
+++ b/src/Test/Logic/UtilitiesTest.cs
@@ -463,6 +463,14 @@ namespace Test.Logic
Assert.AreEqual("ADULT MARK: New friends", s2);
}
+ [TestMethod]
+ public void FixInvalidItalicColonBracketItalic()
+ {
+ var s1 = "[König:] Ich weiß, dass du dagegen" + Environment.NewLine + "bist.";
+ var s2 = HtmlUtil.FixInvalidItalicTags(s1);
+ Assert.AreEqual("[König:] Ich weiß, dass du dagegen" + Environment.NewLine + "bist.", s2);
+ }
+
[TestMethod]
public void FixUnneededSpacesDoubleSpace1()
{
diff --git a/src/libse/Common/HtmlUtil.cs b/src/libse/Common/HtmlUtil.cs
index 871de5819..7c4048024 100644
--- a/src/libse/Common/HtmlUtil.cs
+++ b/src/libse/Common/HtmlUtil.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
@@ -651,6 +652,11 @@ namespace Nikse.SubtitleEdit.Core.Common
text = text.Replace("", string.Empty);
}
+ text = text.Replace("] ", "] ");
+ text = text.Replace(") ", ") ");
+ text = text.Replace("] ", "] ");
+ text = text.Replace(") ", ") ");
+
text = text.Replace(beginTag + beginTag, beginTag);
text = text.Replace(endTag + endTag, endTag);
@@ -852,14 +858,19 @@ namespace Nikse.SubtitleEdit.Core.Common
if (idx > 1)
{
var pre = text.Substring(0, idx + 1).TrimStart();
- text = text.Remove(0, idx + 1);
- text = FixInvalidItalicTags(text).Trim();
- if (text.StartsWith(" ", StringComparison.OrdinalIgnoreCase))
+ var tempText = text.Remove(0, idx + 1);
+
+ if (!tempText.StartsWith(']') && !tempText.StartsWith(')'))
{
- text = Utilities.RemoveSpaceBeforeAfterTag(text, beginTag);
- }
+ text = tempText;
+ text = FixInvalidItalicTags(text).Trim();
+ if (text.StartsWith(" ", StringComparison.OrdinalIgnoreCase))
+ {
+ text = Utilities.RemoveSpaceBeforeAfterTag(text, beginTag);
+ }
- text = pre + " " + text;
+ text = pre + " " + text;
+ }
}
}
}