[touch: 590]

Fixed link inside images switching from visual to wikimarkup.
This commit is contained in:
Cristian Trapattoni 2011-03-14 11:55:11 +01:00
parent 6bc34e925e
commit 574489d476

View file

@ -15,13 +15,6 @@ namespace ScrewTurn.Wiki {
/// </summary> /// </summary>
public static class ReverseFormatter { public static class ReverseFormatter {
/// <summary>
/// Processes order or unorder lists and sublists.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <param name="marker">The marker.</param>
/// <returns>Valid WikiMarkUp text for the lists</returns>
private static string processList(XmlNodeList nodes, string marker) { private static string processList(XmlNodeList nodes, string marker) {
string result = ""; string result = "";
string ul = "*"; string ul = "*";
@ -51,11 +44,6 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
/// <summary>
/// Processes the image.
/// </summary>
/// <param name="node">The node contenent fileName of the image.</param>
/// <returns>The correct path for wikimarup and image</returns>
private static string processImage(XmlNode node) { private static string processImage(XmlNode node) {
string result = ""; string result = "";
if(node.Attributes.Count != 0) { if(node.Attributes.Count != 0) {
@ -71,11 +59,19 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
/// <summary> private static string processLink(string link) {
/// Processes the child Image. string subLink = "";
/// </summary> string[] links = link.Split('=');
/// <param name="nodes">Nodelist from an image.</param> if(links[0] == "GetFile.aspx?File") {
/// <returns>The correct WikiMarkup for the images </returns> subLink += "{UP}";
for(int i = 1; i < links.Length - 1; i++)
subLink += links[i] + "=";
subLink += links[links.Length - 1];
link = subLink;
}
return link;
}
private static string processChildImage(XmlNodeList nodes) { private static string processChildImage(XmlNodeList nodes) {
string image = ""; string image = "";
string p = ""; string p = "";
@ -102,6 +98,8 @@ namespace ScrewTurn.Wiki {
link += attName.Value.ToString(); link += attName.Value.ToString();
} }
} }
link = processLink(link);
image += processImage(node.LastChild); image += processImage(node.LastChild);
url = "|" + target + link; url = "|" + target + link;
} }
@ -112,12 +110,6 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
/// <summary>
/// Processes the table image.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <returns>An auto-image type formmatter</returns>
private static string processTableImage(XmlNodeList nodes) { private static string processTableImage(XmlNodeList nodes) {
string result = ""; string result = "";
foreach(XmlNode node in nodes) { foreach(XmlNode node in nodes) {
@ -160,6 +152,7 @@ namespace ScrewTurn.Wiki {
if(attName.Name.ToString() == "title") if(attName.Name.ToString() == "title")
title += attName.Value.ToString(); title += attName.Value.ToString();
} }
link = processLink(link);
} }
result += processTableImage(node.ChildNodes) + "|" + target + link; result += processTableImage(node.ChildNodes) + "|" + target + link;
} }
@ -168,22 +161,13 @@ namespace ScrewTurn.Wiki {
} }
return result; return result;
} }
/// <summary>
/// Processes the code.
/// </summary>
/// <param name="text">The text.</param>
/// <returns></returns>
private static string processCode(string text) { private static string processCode(string text) {
string result = ""; string result = "";
result = text; result = text;
return result; return result;
} }
/// <summary>
/// Processes the table.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <returns></returns>
private static string processTable(XmlNodeList nodes) { private static string processTable(XmlNodeList nodes) {
string result = ""; string result = "";
@ -207,7 +191,6 @@ namespace ScrewTurn.Wiki {
if(attr.Name.ToLowerInvariant() == "style") style += "style=\"" + attr.Value.ToString() + "\" "; if(attr.Name.ToLowerInvariant() == "style") style += "style=\"" + attr.Value.ToString() + "\" ";
result += "|- " + style + "\r\n" + processTable(node.ChildNodes); result += "|- " + style + "\r\n" + processTable(node.ChildNodes);
//else result += processTable(node.ChildNodes);
break; break;
case "td": case "td":
string styleTd = ""; string styleTd = "";
@ -223,11 +206,7 @@ namespace ScrewTurn.Wiki {
} }
return result; return result;
} }
/// <summary>
/// Processes the child.
/// </summary>
/// <param name="nodes">A XmlNodeList .</param>
/// <returns>The corrispondent WikiMarkup Text</returns>
private static string processChild(XmlNodeList nodes) { private static string processChild(XmlNodeList nodes) {
string result = ""; string result = "";
foreach(XmlNode node in nodes) { foreach(XmlNode node in nodes) {
@ -255,7 +234,6 @@ namespace ScrewTurn.Wiki {
case "u": case "u":
result += ("__" + processChild(node.ChildNodes) + "__"); result += ("__" + processChild(node.ChildNodes) + "__");
break; break;
//break;
case "h1": case "h1":
if(node.HasChildNodes) { if(node.HasChildNodes) {
if(node.FirstChild.NodeType == XmlNodeType.Whitespace) result += ("----\r\n" + processChild(node.ChildNodes)); if(node.FirstChild.NodeType == XmlNodeType.Whitespace) result += ("----\r\n" + processChild(node.ChildNodes));
@ -263,15 +241,12 @@ namespace ScrewTurn.Wiki {
} }
else result += ("----\r\n"); else result += ("----\r\n");
break; break;
//break;
case "h2": case "h2":
result += ("===" + processChild(node.ChildNodes) + "===\r\n"); result += ("===" + processChild(node.ChildNodes) + "===\r\n");
break; break;
//break;
case "h3": case "h3":
result += ("====" + processChild(node.ChildNodes) + "====\r\n"); result += ("====" + processChild(node.ChildNodes) + "====\r\n");
break; break;
//break;
case "h4": case "h4":
result += ("=====" + processChild(node.ChildNodes) + "=====\r\n"); result += ("=====" + processChild(node.ChildNodes) + "=====\r\n");
break; break;
@ -398,6 +373,7 @@ namespace ScrewTurn.Wiki {
string title = ""; string title = "";
bool isInternalLink = false; bool isInternalLink = false;
bool childImg = false; bool childImg = false;
bool isUnknowLink = false;
if(node.FirstChild != null) { if(node.FirstChild != null) {
if(node.FirstChild.Name.ToLowerInvariant() == "img") if(node.FirstChild.Name.ToLowerInvariant() == "img")
childImg = true; childImg = true;
@ -416,19 +392,25 @@ namespace ScrewTurn.Wiki {
title += attName.Value.ToString(); title += attName.Value.ToString();
if(attName.Value.ToString() == "SystemLink".ToLowerInvariant()) if(attName.Value.ToString() == "SystemLink".ToLowerInvariant())
isInternalLink = true; isInternalLink = true;
if(attName.Value.ToString().ToLowerInvariant() == "unknownlink")
isUnknowLink = true;
} }
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;
} }
} }
if(isInternalLink) { if(isInternalLink) {
string[] splittedLink = link.Split('='); string[] splittedLink = link.Split('=');
link = "c:" + splittedLink[1]; link = "c:" + splittedLink[1];
} }
else
link = processLink(link);
if((!anchor) && (!isTable) && (!childImg)) if((!anchor) && (!isTable) && (!childImg) && (!isUnknowLink))
if(title != link) if(title != link)
result += "[" + target + link + "|" + processChild(node.ChildNodes) + "]"; result += "[" + target + link + "|" + processChild(node.ChildNodes) + "]";
else else
@ -450,13 +432,7 @@ namespace ScrewTurn.Wiki {
return result; return result;
} }
/// <summary>
/// Froms the HTML.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>valid XML Document</returns>
private static XmlDocument FromHTML(TextReader reader) { private static XmlDocument FromHTML(TextReader reader) {
// setup SgmlReader // setup SgmlReader
Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader(); Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader();
sgmlReader.DocType = "HTML"; sgmlReader.DocType = "HTML";
@ -479,10 +455,10 @@ namespace ScrewTurn.Wiki {
/// <param name="html">The input HTML.</param> /// <param name="html">The input HTML.</param>
/// <returns>The corresponding WikiMarkup.</returns> /// <returns>The corresponding WikiMarkup.</returns>
public static string ReverseFormat(string html) { public static string ReverseFormat(string html) {
StringReader strReader = new StringReader(html); StringReader strReader = new StringReader(html);
XmlDocument x = FromHTML((TextReader)strReader); XmlDocument x = FromHTML((TextReader)strReader);
return processChild(x.FirstChild.ChildNodes); if(x != null) return processChild(x.FirstChild.ChildNodes);
else return "";
} }
} }
} }