diff --git a/Core-Tests/ReverseFormatterTests.cs b/Core-Tests/ReverseFormatterTests.cs index b473111..8677a00 100644 --- a/Core-Tests/ReverseFormatterTests.cs +++ b/Core-Tests/ReverseFormatterTests.cs @@ -10,35 +10,37 @@ namespace ScrewTurn.Wiki.Tests { public class ReverseFormatterTests { [Test] - //[TestCase("text", "'''text'''")] - //[TestCase("text", "'''text'''")] - //[TestCase("text", "''text''")] - //[TestCase("text", "''text''")] - //[TestCase("text", "__text__")] - //[TestCase("text", "--text--")] - //[TestCase("

text

", "==text==")] - //[TestCase("

text

", "===text===")] - //[TestCase("

text

", "====text====")] - //[TestCase("

text", "=====text=====")] - //[TestCase("text", "text")] - //[TestCase("text", "text")] - //[TestCase("
text
", "@@text@@")] - //[TestCase("text", "{{'''text'''}}")] - //[TestCase("
text
", "(((text))){br}")] - //[TestCase("
text
", "text{br}")] - [TestCase("
  1. 1
  2. 2
", "# 1{br}# 2{br}{br}")] - [TestCase("", "* 1{br}* 2{br}{br}")] - [TestCase("", "* it 1{br}** 1.1{br}** 1.2{br}* it2{br}{br}")] - [TestCase("", "* it 1{br}*# 1.1{br}*# 1.2{br}* it2{br}{br}")] - //[TestCase("I'm an anchor", "[anchor|#init]I'm an anchor")] - //[TestCase("This recall an anchor", "[#init|This recall an anchor]")] - //[TestCase("BIG TITLE", "[^google.com|BIG TITLE]")] - //[TestCase("try to esc tag", "try to esc tag")] - //[TestCase("
\"left

leftalign

", "[imageleft|leftalign|{UP(MainPage)}image.png|^www.link.com]{br}")] - //[TestCase("\"inlineimage\"", "[image|inlineimage|{UP(MainPage)}image.png]{br}")] - //[TestCase("\"description\"", "[image|description|{UP(MainPage)}image.png|^www.google.it]{br}")] - //[TestCase("
\"autoalign\"

autoalign

", "[imageauto|autoalign|{UP(MainPage)}image.png]{br}")] - //[TestCase("
\"Auto

Auto align

", "[imageauto|Auto align|{UP(MainPage)}image.png|www.link.com]{br}")] + [TestCase("text", "'''text'''")] + [TestCase("text", "'''text'''")] + [TestCase("text", "''text''")] + [TestCase("text", "''text''")] + [TestCase("text", "__text__")] + [TestCase("text", "--text--")] + [TestCase("

text

", "==text==")] + [TestCase("

text

", "===text===")] + [TestCase("

text

", "====text====")] + [TestCase("

text", "=====text=====")] + [TestCase("text", "text")] + [TestCase("text", "text")] + [TestCase("
text
", "@@text@@")] + [TestCase("text", "{{'''text'''}}")] + [TestCase("
text
", "(((text))){br}")] + [TestCase("
text
", "text{br}")] + [TestCase("
  1. 1
  2. 2
  3. 3
    1. 3.1
    2. 3.2
      1. 3.2.1
    3. 3.3
  4. 4

", "# 1\r\n# 2\r\n# 3\r\n## 3.1\r\n## 3.2\r\n### 3.2.1\r\n## 3.3\r\n# 4\r\n# \r\n{br}{br}")] + [TestCase("
  1. 1
  2. 2
", "# 1\r\n# 2\r\n{br}")] + [TestCase("", "* 1\r\n* 2\r\n{br}")] + [TestCase("", "* Punto 1\r\n* Punto 2\r\n* Punto 3\r\n* Punto 4\r\n* Punto 5\r\n{br}")] + [TestCase("", "* it 1\r\n** 1.1\r\n** 1.2\r\n* it2\r\n{br}")] + [TestCase("", "* it 1\r\n*# 1.1\r\n*# 1.2\r\n* it2\r\n{br}")] + [TestCase("I'm an anchor", "[anchor|#init]I'm an anchor")] + [TestCase("This recall an anchor", "[#init|This recall an anchor]")] + [TestCase("BIG TITLE", "[^google.com|BIG TITLE]")] + [TestCase("try to esc tag", "try to esc tag")] + [TestCase("
\"left

leftalign

", "[imageleft|leftalign|{UP(MainPage)}image.png|^www.link.com]{br}")] + [TestCase("\"inlineimage\"", "[image|inlineimage|{UP(MainPage)}image.png]{br}")] + [TestCase("\"description\"", "[image|description|{UP(MainPage)}image.png|^www.google.it]{br}")] + [TestCase("
\"autoalign\"

autoalign

", "[imageauto|autoalign|{UP(MainPage)}image.png]{br}")] + [TestCase("
\"Auto

Auto align

", "[imageauto|Auto align|{UP(MainPage)}image.png|www.link.com]{br}")] public void PlainTest(string input, string output) { Assert.AreEqual(output, ReverseFormatter.ReverseFormat(input)); } diff --git a/Core/ReverseFormatter.cs b/Core/ReverseFormatter.cs index 62a621b..eadf527 100644 --- a/Core/ReverseFormatter.cs +++ b/Core/ReverseFormatter.cs @@ -90,13 +90,22 @@ namespace ScrewTurn.Wiki { string ul = "*"; string ol = "#"; foreach(XmlNode node in nodes) { - foreach(XmlNode child in node) { - if(child.Name.ToString() == "ol") - result += marker + " " +processList(child.ChildNodes, marker + ol); - if(child.Name.ToString() == "ul") - result += marker + " "+ processList(child.ChildNodes, marker + ul); - else - result += processChild(child.ChildNodes); + if(node.Name.ToString() == "li"){ + foreach(XmlNode child in node.ChildNodes) { + switch(child.Name.ToString()){ + case "ol": + result += processList(child.ChildNodes, marker + ol); + break; + case "ul": + result += processList(child.ChildNodes, marker + ul); + break; + default: + StringReader a = new StringReader(child.InnerText); + XmlDocument n = FromHTML((TextReader)a); + result += marker + " " + processChild(n.ChildNodes) + "\r\n"; + break; + } + } } } return result; @@ -174,6 +183,9 @@ namespace ScrewTurn.Wiki { } else { switch(node.Name.ToLowerInvariant()) { + case "html": + result += processChild(node.ChildNodes); + break; case "b": case "strong": result += ("'''" + processChild(node.ChildNodes) + "'''");