Fixed some problems image's autoalign and ul, ol
This commit is contained in:
parent
ed62d52959
commit
d02f5bf845
2 changed files with 130 additions and 58 deletions
|
@ -24,14 +24,20 @@ namespace ScrewTurn.Wiki.Tests {
|
||||||
[TestCase("<sub>text</sub>", "<sub>text</sub>")]
|
[TestCase("<sub>text</sub>", "<sub>text</sub>")]
|
||||||
[TestCase("<pre><b>text</b></pre>", "@@text@@")]
|
[TestCase("<pre><b>text</b></pre>", "@@text@@")]
|
||||||
[TestCase("<code><b>text</b></code>", "{{'''text'''}}")]
|
[TestCase("<code><b>text</b></code>", "{{'''text'''}}")]
|
||||||
[TestCase("<div class=\"box\">text</div>","(((text))){br}")]
|
[TestCase("<div class=\"box\">text</div>", "(((text))){br}")]
|
||||||
[TestCase("<div>text</div>", "text{br}")]
|
[TestCase("<div>text</div>", "text{br}")]
|
||||||
[TestCase("<ol><li>1</li><li>2</li></ol>","{br}# 1{br}# 2{br}{br}")]
|
[TestCase("<ol><li>1</li><li>2</li></ol>", "# 1{br}# 2{br}{br}")]
|
||||||
[TestCase("<ul><li>1</li><li>2</li></ul>", "{br}* 1{br}* 2{br}{br}")]
|
[TestCase("<ul><li>1</li><li>2</li></ul>", "* 1{br}* 2{br}{br}")]
|
||||||
[TestCase("<a id=\"Init\" />I'm an anchor", "[anchor|#init]I'm an anchor")]
|
//[TestCase("<ul><li>it 1<ul><li>1.1</li><li>1.2</li></ul></li><li>it2</li></ul>", "* it 1{br}** 1.1{br}** 1.2{br}* it2{br}{br}")]
|
||||||
[TestCase("<a class=\"internallink\" href=\"#init\" title=\"This recall an anchor\">This recall an anchor</a>", "[#init|This recall an anchor]")]
|
//[TestCase("<ul><li>it 1<ol><li>1.1</li><li>1.2</li></ol></li><li>it2</li></ul>", "* it 1{br}*# 1.1{br}*# 1.2{br}* it2{br}{br}")]
|
||||||
[TestCase("<a class=\"externallink\" href=\"google.com\" title=\"BIG TITLE\" target=\"_blank\">BIG TITLE</a>","[^google.com|BIG TITLE]")]
|
[TestCase("<html><a id=\"Init\" />I'm an anchor</html>", "[anchor|#init]I'm an anchor")]
|
||||||
[TestCase("<esc>try to esc tag</esc>","<esc>try to esc tag</esc>")]
|
[TestCase("<html><a class=\"internallink\" href=\"#init\" title=\"This recall an anchor\">This recall an anchor</a></html>", "[#init|This recall an anchor]")]
|
||||||
|
[TestCase("<html><a class=\"externallink\" href=\"google.com\" title=\"BIG TITLE\" target=\"_blank\">BIG TITLE</a></html>", "[^google.com|BIG TITLE]")]
|
||||||
|
[TestCase("<esc>try to esc tag</esc>", "<esc>try to esc tag</esc>")]
|
||||||
|
[TestCase("<div class=\"imageleft\"><a target=\"_blank\" href=\"www.link.com\" title=\"left Align\"><img class=\"image\" src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"left Align\" /></a><p class=\"imagedescription\">leftalign</p></div>", "[imageleft|leftalign|{UP(MainPage)}image.png|^www.link.com]{br}")]
|
||||||
|
[TestCase("<img src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"inlineimage\" />", "[image|inlineimage|{UP(MainPage)}image.png]{br}")]
|
||||||
|
[TestCase("<table class=\"imageauto\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr><td><img class=\"image\" src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"autoalign\" /><p class=\"imagedescription\">autoalign</p></td></tr></tbody></table>", "[imageauto|autoalign|{UP(MainPage)}image.png]{br}")]
|
||||||
|
[TestCase("<table class=\"imageauto\" cellpadding=\"0\" cellspacing=\"0\"><tbody><tr><td><a href=\"www.link.com\" title=\"Auto align\"><img class=\"image\" src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"Auto align\" /></a><p class=\"imagedescription\">Auto align</p></td></tr></tbody></table>", "[imageauto|Auto align|{UP(MainPage)}image.png|^www.link.com]")]
|
||||||
public void PlainTest(string input, string output) {
|
public void PlainTest(string input, string output) {
|
||||||
Assert.AreEqual(output, ReverseFormatter.ReverseFormat(input));
|
Assert.AreEqual(output, ReverseFormatter.ReverseFormat(input));
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,61 @@ namespace ScrewTurn.Wiki {
|
||||||
//private static string result = "";
|
//private static string result = "";
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the sub list text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="node">The node.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string processSubListText(XmlNode node) {
|
||||||
|
string result = "";
|
||||||
|
if(node.HasChildNodes)
|
||||||
|
result += processChild(node.ChildNodes);
|
||||||
|
else
|
||||||
|
result += node.InnerText.ToString();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Processes the list.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="nodes">The nodes.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static string processList(XmlNodeList nodes) {
|
||||||
|
string result = "";
|
||||||
|
string ul = "*";
|
||||||
|
string ol = "#";
|
||||||
|
|
||||||
|
foreach(XmlNode node in nodes) {
|
||||||
|
string marker = "";
|
||||||
|
string text = "";
|
||||||
|
|
||||||
|
if(node.NodeType.ToString().ToLowerInvariant() == "text")
|
||||||
|
{
|
||||||
|
text += " " + processSubListText(node) + "{br}";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch(node.Name.ToLowerInvariant().ToString()) {
|
||||||
|
case "li":
|
||||||
|
if(node.ParentNode.Name.ToLowerInvariant().ToString() == "ul")
|
||||||
|
marker += ul + processList(node.ChildNodes);
|
||||||
|
if(node.ParentNode.Name.ToLowerInvariant().ToString() == "ol")
|
||||||
|
marker += ol + processList(node.ChildNodes);
|
||||||
|
//else
|
||||||
|
// marker += "PIPPO2" + processList(node.ChildNodes);
|
||||||
|
break;
|
||||||
|
case "ol":
|
||||||
|
marker += ol + processList(node.ChildNodes);
|
||||||
|
break;
|
||||||
|
case "ul":
|
||||||
|
marker += ul + processList(node.ChildNodes);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result += marker + text;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Processes the image.
|
/// Processes the image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -92,7 +147,7 @@ namespace ScrewTurn.Wiki {
|
||||||
if(attName.Name.ToString() == "src") {
|
if(attName.Name.ToString() == "src") {
|
||||||
string[] path = attName.Value.ToString().Split('=');
|
string[] path = attName.Value.ToString().Split('=');
|
||||||
//result += "|" + processChild(node.ChildNodes);
|
//result += "|" + processChild(node.ChildNodes);
|
||||||
result += "{" + "UP(" + path[1].Split('&')[0] + ")}" + path[2];
|
result += "{"+"UP("+ path[1].Split('&')[0] +")}" + path[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,14 +264,20 @@ namespace ScrewTurn.Wiki {
|
||||||
case "br":
|
case "br":
|
||||||
result += ("{br}" + processChild(node.ChildNodes));
|
result += ("{br}" + processChild(node.ChildNodes));
|
||||||
break;
|
break;
|
||||||
case "ol":
|
|
||||||
result += processChild(node.ChildNodes) + "{br}";
|
|
||||||
break;
|
|
||||||
case "ul":
|
|
||||||
result += processChild(node.ChildNodes) + "{br}";
|
|
||||||
break;
|
|
||||||
case "table":
|
case "table":
|
||||||
result += processChild(node.ChildNodes);
|
string image = "";
|
||||||
|
bool isImage = false;
|
||||||
|
foreach(XmlAttribute attName in node.Attributes) {
|
||||||
|
if(attName.Value.ToString() == "imageauto") {
|
||||||
|
isImage = true;
|
||||||
|
image += "[imageauto|" + processChild(node.ChildNodes) + "]{br}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isImage){
|
||||||
|
result += image;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else result += processChild(node.ChildNodes);
|
||||||
break;
|
break;
|
||||||
case "tbody":
|
case "tbody":
|
||||||
result += processChild(node.ChildNodes);
|
result += processChild(node.ChildNodes);
|
||||||
|
@ -227,16 +288,14 @@ namespace ScrewTurn.Wiki {
|
||||||
case "td":
|
case "td":
|
||||||
result += processChild(node.ChildNodes);
|
result += processChild(node.ChildNodes);
|
||||||
break;
|
break;
|
||||||
|
case "ol":
|
||||||
|
result += processList(node.ChildNodes) + "{br}";
|
||||||
|
break;
|
||||||
|
case "ul":
|
||||||
|
result += processList(node.ChildNodes) + "{br}";
|
||||||
|
break;
|
||||||
case "li":
|
case "li":
|
||||||
if (node.ParentNode.Name.ToLowerInvariant() == "ol")
|
result += processChild(node.ChildNodes);
|
||||||
result += ("#" + " "+processChild(node.ChildNodes) + "{br}");
|
|
||||||
else if (node.ParentNode.Name.ToLowerInvariant() == "ul")
|
|
||||||
result += ("*" + " "+ processChild(node.ChildNodes) + "{br}");
|
|
||||||
else if(node.ParentNode.Name.ToLowerInvariant() == "li")
|
|
||||||
if(node.ParentNode.ParentNode.Name.ToLowerInvariant() == "ol")
|
|
||||||
result += ("*#" + " " + processChild(node.ChildNodes));
|
|
||||||
else if(node.ParentNode.ParentNode.Name.ToLowerInvariant() == "ul")
|
|
||||||
result += ("#*" + " " + processChild(node.ChildNodes));
|
|
||||||
break;
|
break;
|
||||||
case "sup":
|
case "sup":
|
||||||
result += ("<sup>" + processChild(node.ChildNodes) + "</sup>");
|
result += ("<sup>" + processChild(node.ChildNodes) + "</sup>");
|
||||||
|
@ -264,9 +323,9 @@ namespace ScrewTurn.Wiki {
|
||||||
result += "[imageleft" + processChildImage(node.ChildNodes) + "]{br}";
|
result += "[imageleft" + processChildImage(node.ChildNodes) + "]{br}";
|
||||||
}
|
}
|
||||||
if(attName.Value.ToString() == "imageright")
|
if(attName.Value.ToString() == "imageright")
|
||||||
result += "[imageleft" + processChildImage(node.ChildNodes) + "]{br}";
|
result += "[imageright" + processChildImage(node.ChildNodes) + "]{br}";
|
||||||
if(attName.Value.ToString() == "imageauto")
|
if(attName.Value.ToString() == "imageauto")
|
||||||
result += "[imageleft" + processChildImage(node.ChildNodes) + "]{br}";
|
result += "[imageauto" + processChildImage(node.ChildNodes) + "]{br}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -274,21 +333,26 @@ namespace ScrewTurn.Wiki {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "img":
|
case "img":
|
||||||
if(node.Attributes.Count != 0) {
|
string description = "";
|
||||||
XmlAttributeCollection attribute = node.Attributes;
|
bool hasClass = false;
|
||||||
foreach(XmlAttribute attName in attribute) {
|
if(node.Attributes.Count != 0){
|
||||||
//if(attName.Name.ToString() == "src") {
|
foreach(XmlAttribute attName in node.Attributes) {
|
||||||
// string[] path = attName.Value.ToString().Split('=');
|
if(attName.Name.ToString() == "alt")
|
||||||
//result += "|" + processChild(node.ChildNodes);
|
description = attName.Value.ToString();
|
||||||
result += processImage(node);
|
if(attName.Name.ToString() == "class")
|
||||||
//}
|
hasClass = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!hasClass)
|
||||||
|
result += "[image|" + description + "|" + processImage(node) + "]{br}";
|
||||||
|
else
|
||||||
|
result += description+"|"+processImage(node);
|
||||||
break;
|
break;
|
||||||
case "a":
|
case "a":
|
||||||
string link="";
|
string link="";
|
||||||
string target="";
|
string target="";
|
||||||
string title="";
|
string title="";
|
||||||
|
// if(node.FirstChild.Name.ToLowerInvariant() != "img") {
|
||||||
if(node.Attributes.Count != 0) {
|
if(node.Attributes.Count != 0) {
|
||||||
XmlAttributeCollection attribute = node.Attributes;
|
XmlAttributeCollection attribute = node.Attributes;
|
||||||
foreach(XmlAttribute attName in attribute) {
|
foreach(XmlAttribute attName in attribute) {
|
||||||
|
@ -300,7 +364,7 @@ namespace ScrewTurn.Wiki {
|
||||||
if(attName.Name.ToString() == "title")
|
if(attName.Name.ToString() == "title")
|
||||||
title += attName.Value.ToString();
|
title += attName.Value.ToString();
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
anchor = true;
|
anchor = true;
|
||||||
result += "[anchor|#" + attName.Value.ToString().ToLowerInvariant() + "]" + processChild(node.ChildNodes);
|
result += "[anchor|#" + attName.Value.ToString().ToLowerInvariant() + "]" + processChild(node.ChildNodes);
|
||||||
break;
|
break;
|
||||||
|
@ -312,6 +376,8 @@ namespace ScrewTurn.Wiki {
|
||||||
else
|
else
|
||||||
result += "[" + target + link + "|" + "]" + processChild(node.ChildNodes);
|
result += "[" + target + link + "|" + "]" + processChild(node.ChildNodes);
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
|
//else processChild(node.ChildNodes);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue