Fixed problems with bold and italic in lists
This commit is contained in:
parent
c458a8ac67
commit
a39315a3cd
2 changed files with 18 additions and 26 deletions
|
@ -13,6 +13,7 @@ namespace ScrewTurn.Wiki.Tests {
|
|||
[TestCase("<b>text</b>", "'''text'''")]
|
||||
[TestCase("<strong>text</strong>", "'''text'''")]
|
||||
[TestCase("<i>text</i>", "''text''")]
|
||||
[TestCase("<ul><li>prova <b>pippo</b></li><li>riga2</li></ul>", "* prova '''pippo'''\r\n* riga2\r\n")]
|
||||
[TestCase("<em>text</em>", "''text''")]
|
||||
[TestCase("<u>text</u>", "__text__")]
|
||||
[TestCase("<s>text</s>", "--text--")]
|
||||
|
@ -26,8 +27,8 @@ namespace ScrewTurn.Wiki.Tests {
|
|||
[TestCase("<code><b>text</b></code>", "{{'''text'''}}")]
|
||||
[TestCase("<div class=\"box\">text</div>", "\r\n(((text)))\r\n")]
|
||||
[TestCase("<div>text</div>", "\r\ntext\r\n")]
|
||||
[TestCase("<html>riga1\r\n<b>riga2</b>\r\nriga3</html>","riga1\r\n'''riga2'''\r\nriga3")]
|
||||
[TestCase("<html><ol><li>1</li><li>2</li><li>3<ol><li>3.1</li><li>3.2<ol><li>3.2.1</li></ol></li><li>3.3</li></ol></li><li>4<br /></li></ol><br /></html>", "# 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\r\n")]
|
||||
[TestCase("<html>riga1\r\n<b>riga2</b>\r\nriga3</html>", "riga1\r\n'''riga2'''\r\nriga3")]
|
||||
[TestCase("<html><ol><li>1</li><li>2</li><li>3<ol><li>3.1</li><li>3.2<ol><li>3.2.1</li></ol></li><li>3.3</li></ol></li><li>4<br />ciao</li></ol><br /></html>", "# 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\nciao\r\n\r\n")]
|
||||
[TestCase("<ol><li>1</li><li>2</li></ol>", "# 1\r\n# 2\r\n")]
|
||||
[TestCase("<ul><li>1</li><li>2</li></ul>", "* 1\r\n* 2\r\n")]
|
||||
[TestCase("<html><ul><li>Punto 1</li><li>Punto 2</li><li>Punto 3</li><li>Punto 4</li><li>Punto 5</li></ul></html>", "* Punto 1\r\n* Punto 2\r\n* Punto 3\r\n* Punto 4\r\n* Punto 5\r\n")]
|
||||
|
|
|
@ -27,30 +27,22 @@ namespace ScrewTurn.Wiki {
|
|||
string ul = "*";
|
||||
string ol = "#";
|
||||
foreach(XmlNode node in nodes) {
|
||||
if(node.Name.ToString() == "li") {
|
||||
string text = "";
|
||||
if(node.Name == "li") {
|
||||
foreach(XmlNode child in node.ChildNodes) {
|
||||
if(child.NodeType == XmlNodeType.Text) {
|
||||
string ie = child.Value.ToString();
|
||||
ie = ie.Replace("\r", string.Empty).Replace("\n", string.Empty);
|
||||
child.Value = ie;
|
||||
if(child.Name != "ol" && child.Name != "ul") {
|
||||
StringReader a = new StringReader(child.OuterXml);
|
||||
XmlDocument n = FromHTML((TextReader)a);
|
||||
text += processChild(n.ChildNodes);
|
||||
}
|
||||
switch(child.Name.ToString()) {
|
||||
case "ol":
|
||||
result += processList(child.ChildNodes, marker + ol);
|
||||
break;
|
||||
case "ul":
|
||||
result += processList(child.ChildNodes, marker + ul);
|
||||
break;
|
||||
case "br":
|
||||
StringReader aa = new StringReader(child.OuterXml);
|
||||
XmlDocument ne = FromHTML((TextReader)aa);
|
||||
result += processChild(ne.ChildNodes);
|
||||
break;
|
||||
default:
|
||||
StringReader a = new StringReader(child.OuterXml);
|
||||
XmlDocument n = FromHTML((TextReader)a);
|
||||
result += marker + " " + processChild(n.ChildNodes) + "\r\n";
|
||||
break;
|
||||
}
|
||||
result += marker + " " + text + "\r\n";
|
||||
foreach(XmlNode child in node.ChildNodes) {
|
||||
if(child.Name.ToString() == "ol"){
|
||||
result += processList(child.ChildNodes, marker + ol);
|
||||
}
|
||||
if (child.Name.ToString() == "ul") {
|
||||
result += processList(child.ChildNodes, marker + ul);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +50,6 @@ namespace ScrewTurn.Wiki {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Processes the image.
|
||||
/// </summary>
|
||||
|
@ -70,7 +61,7 @@ namespace ScrewTurn.Wiki {
|
|||
foreach(XmlAttribute attName in node.Attributes) {
|
||||
if((attName.Name.ToString() == "src") || (attName.Value.ToString().ToLowerInvariant() == "Image")) {
|
||||
string[] path = attName.Value.ToString().Split('=');
|
||||
result += "{" + "UP(" + path[1].Split('&')[0] + ")}" + path[2];
|
||||
result += "{" + "UP(" + path[1].Split('&')[0] + ")}" + path[path.Length-1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue