Fixed autoalign e inline description

This commit is contained in:
Cristian Trapattoni 2011-03-02 09:53:34 +01:00
parent 087f015b79
commit c458a8ac67
2 changed files with 5 additions and 27 deletions

View file

@ -39,10 +39,10 @@ namespace ScrewTurn.Wiki.Tests {
[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>", "\r\n[imageleft|leftalign|{UP(MainPage)}image.png|^www.link.com]\r\n")]
[TestCase("<img src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"inlineimage\" />", "[image||{UP(MainPage)}image.png]\r\n")]
[TestCase("<a target=\"_blank\" href=\"www.google.it\" title=\"description\"><img src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"description\" /></a>", "[image||{UP(MainPage)}image.png|^www.google.it]\r\n")]
[TestCase("<img src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"inlineimage\" />", "[image|inlineimage|{UP(MainPage)}image.png]\r\n")]
[TestCase("<a target=\"_blank\" href=\"www.google.it\" title=\"description\"><img src=\"GetFile.aspx?Page=MainPage&File=image.png\" alt=\"description\" /></a>", "[image|description|{UP(MainPage)}image.png|^www.google.it]\r\n")]
[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]\r\n")]
[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||{UP(MainPage)}image.png|www.link.com]\r\n")]
[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]\r\n")]
public void PlainTest(string input, string output) {
Assert.AreEqual(output, ReverseFormatter.ReverseFormat(input));
}

View file

@ -16,24 +16,6 @@ namespace ScrewTurn.Wiki {
public static class ReverseFormatter {
/// <summary>
/// Searches the description.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <returns></returns>
private static string searchDescription (XmlNodeList nodes){
string description = "";
foreach (XmlNode n in nodes){
if(n.Name.ToLowerInvariant() == "p") {
foreach(XmlAttribute att in n.Attributes) {
if(att.Value.ToLowerInvariant().ToString() == "imagedescription")
description += processChild(n.ChildNodes);
}
}
}
return description;
}
/// <summary>
/// Processes order or unorder lists and sublists.
/// </summary>
@ -148,7 +130,6 @@ namespace ScrewTurn.Wiki {
/// <returns>The corrispondent WikiMarkup Text</returns>
private static string processChild(XmlNodeList nodes) {
string result = "";
bool isImage = false;
foreach(XmlNode node in nodes) {
bool anchor = false;
if(node.NodeType == XmlNodeType.Text) {
@ -222,6 +203,7 @@ namespace ScrewTurn.Wiki {
result += ("\r\n" + processChild(node.ChildNodes));
break;
case "table":
bool isImage = false;
string image = "";
foreach(XmlAttribute attName in node.Attributes) {
if(attName.Value.ToString() == "imageauto") {
@ -243,10 +225,6 @@ namespace ScrewTurn.Wiki {
result += processChild(node.ChildNodes);
break;
case "td":
if(isImage) {
result += processChildImage(node.ChildNodes);
}
else
result += processChild(node.ChildNodes);
break;
case "ol":
@ -304,7 +282,7 @@ namespace ScrewTurn.Wiki {
if(node.Attributes.Count != 0) {
foreach(XmlAttribute attName in node.Attributes) {
if(attName.Name.ToString() == "alt")
description = searchDescription(node.ParentNode.ChildNodes);
description = attName.Value.ToString();
//description = attName.Value.ToString();
if(attName.Name.ToString() == "class")
hasClass = true;