From 3b656f81aa36b2abc698edcde7b6e6f028d1b2e3 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Mon, 14 Jun 2021 21:06:25 +0200 Subject: [PATCH] More assa style toggle --- src/libse/Common/HtmlUtil.cs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/libse/Common/HtmlUtil.cs b/src/libse/Common/HtmlUtil.cs index e81c8ad46..bdf70d447 100644 --- a/src/libse/Common/HtmlUtil.cs +++ b/src/libse/Common/HtmlUtil.cs @@ -892,25 +892,31 @@ namespace Nikse.SubtitleEdit.Core.Common if (assa) { var onOffTags = new List { "i", "b", "u", "s", "be" }; - if (wholeLine) + if (onOffTags.Contains(tag)) { - onOffTags.Clear(); - } - - if (text.Contains("\\" + tag)) - { - if (onOffTags.Contains(tag)) + if (text.Contains($"\\{tag}1")) { text = text.Replace($"{{\\{tag}1}}", string.Empty); text = text.Replace($"{{\\{tag}0}}", string.Empty); + text = text.Replace($"\\{tag}1", string.Empty); + text = text.Replace($"\\{tag}0", string.Empty); + } + else + { + text = wholeLine ? $"{{\\{tag}1}}{text}" : $"{{\\{tag}1}}{text}{{\\{tag}0}}"; } - text = text.Replace($"{{\\{tag}1}}", string.Empty); - - text = text.Replace($"\\{tag}1", string.Empty); } else { - text = onOffTags.Contains(tag) || !wholeLine ? $"{{\\{tag}1}}{text}{{\\{tag}0}}" : $"{{\\{tag}1}}{text}"; + if (text.Contains($"\\{tag}")) + { + text = text.Replace($"{{\\{tag}}}", string.Empty); + text = text.Replace($"\\{tag}", string.Empty); + } + else + { + text = $"{{\\{tag}}}{text}"; + } } return text;