Added table formattation

This commit is contained in:
Cristian Trapattoni 2011-03-02 17:39:22 +01:00
parent 55b1cfcc27
commit 228acd32df
2 changed files with 59 additions and 10 deletions

View file

@ -858,7 +858,6 @@ namespace ScrewTurn.Wiki {
}
}
if(!bareBones) {
match = TableRegex.Match(sb.ToString());
while(match.Success) {
if(!IsNoWikied(match.Index, noWikiBegin, noWikiEnd, out end)) {
@ -868,7 +867,6 @@ namespace ScrewTurn.Wiki {
ComputeNoWiki(sb.ToString(), ref noWikiBegin, ref noWikiEnd);
match = TableRegex.Match(sb.ToString(), end);
}
}
// Strip out all comments
if(!bareBones) {

View file

@ -112,11 +112,53 @@ namespace ScrewTurn.Wiki {
return result;
}
private static string processCode(string text) {
string result = "";
result = text;
return result;
}
/// <summary>
/// Processes the table.
/// </summary>
/// <param name="nodes">The nodes.</param>
/// <returns></returns>
private static string processTable(XmlNodeList nodes) {
string result = "";
bool isLast = false;
foreach(XmlNode node in nodes) {
if(node == node.ParentNode.LastChild) isLast = true;
switch (node.Name.ToLowerInvariant()){
case "thead":
result += processTable(node.ChildNodes) + "|-\r\n";
break;
case "th":
result += "! " + processChild(node.ChildNodes) + "\r\n";
break;
case "caption":
result += "|+ "+ processChild(node.ChildNodes);
break;
case "tbody":
result += processTable(node.ChildNodes) + "";
break;
case "tr":
string style = "";
foreach(XmlAttribute attr in node.Attributes) {
if(attr.Name.ToLowerInvariant() == "style") style += "style=\"" + attr.Value.ToString() + "\" ";
}
if(!isLast) result += processTable(node.ChildNodes) + "|-" + style + "\r\n";
else result += processTable(node.ChildNodes);
break;
case "td":
result += "| " + processChild(node.ChildNodes) + "\r\n";
break;
}
}
return result;
}
/// <summary>
/// Processes the child.
/// </summary>
@ -199,18 +241,27 @@ namespace ScrewTurn.Wiki {
case "table":
bool isImage = false;
string image = "";
string border = "";
string background = "";
string cellspacing = "";
string cellpadding = "";
foreach(XmlAttribute attName in node.Attributes) {
if(attName.Value.ToString() == "imageauto") {
isImage = true;
image += "[imageauto|" + processChild(node.ChildNodes) + "]\r\n";
}
if(attName.Name.ToLowerInvariant() == "border") border += "border=\""+ attName.Value.ToString() + "\" ";
if(attName.Name.ToLowerInvariant() == "bgcolor") background += "bgcolor=\"" + attName.Value.ToString() + "\" ";
if(attName.Name.ToLowerInvariant() == "cellspacing") cellpadding += "cellpadding=\"" + attName.Value.ToString() + "\" ";
if(attName.Name.ToLowerInvariant() == "cellspacing") cellspacing += "cellspacing=\"" + attName.Value.ToString() + "\" ";
}
if(isImage) {
result += image;
isImage = false;
break;
}
else result += processChild(node.ChildNodes);
else result += "{| " + border + background + cellpadding + cellspacing + "\r\n" + processTable(node.ChildNodes) + "|}";
break;
case "tbody":
result += processChild(node.ChildNodes);