Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestMethod]
- [DataRow("Foo<i></i>bar")]
- [DataRow("Foo<i> </i>bar")]
- [DataRow("<i>Foo</i> <i>bar</i>", "<i>Foobar</i>")]
- // [DataRow("Foo<b> </b>bar")]
- // [DataRow("Foo<u> </u>bar")]
- // [DataRow("Foo<font color=\"#808080\"> </font>bar")]
- // [DataRow("Foo<font color=\"#808080\"></font>bar")]
- public void FixInvalidItalicEmptyTagTest(string input, string expected = "Foobar")
- {
- Assert.AreEqual(expected, HtmlUtil.FixInvalidItalicTags(input));
- }
- ...............
- // <i>foo</i><i>bar</i> => <i>foobar</i>
- // <i>foo</i> <i>bar</i> => <i>foo bar</i>
- // text = text.Replace("</i><i>", string.Empty); (handle bellow)
- text = text.Replace("</i> <i>", " ");
- var l = 0;
- var closeCount = 0;
- for (var r = 0; r < text.Length; r++)
- {
- if (text[r] == '<' && text[l] != '<')
- {
- l = r;
- }
- else if (text[r] == '>' && text[l] == '<' && ++closeCount == 2)
- {
- var st = new StrippableText(text.Substring(l, r - l + 1));
- // no formattable text in between the tags e.g: ...<i> </i>...
- if (string.IsNullOrWhiteSpace(st.StrippedText) &&
- st.OriginalText.EndsWith("<i>", StringComparison.Ordinal) &&
- st.OriginalText.StartsWith("</i>", StringComparison.Ordinal))
- {
- text = text.Remove(l, r - l + 1);
- r = l - 1;
- closeCount = 0;
- }
- else
- {
- // start counting from the last found tag
- // For example in "<i>Foo</i> <i>bar</i>" Skip first tag
- l = text.LastIndexOf('<', r - 1);
- closeCount -= 1;
- }
- }
- }
- return preTags + text;
- }
Add Comment
Please, Sign In to add comment