Fixed XML.WhiteSpace and empty nodes.
This commit is contained in:
parent
c732a7a909
commit
e7c1ad698e
1 changed files with 46 additions and 32 deletions
|
@ -24,11 +24,23 @@ namespace ScrewTurn.Wiki {
|
||||||
if(node.Name == "li") {
|
if(node.Name == "li") {
|
||||||
foreach(XmlNode child in node.ChildNodes) {
|
foreach(XmlNode child in node.ChildNodes) {
|
||||||
if(child.Name != "ol" && child.Name != "ul") {
|
if(child.Name != "ol" && child.Name != "ul") {
|
||||||
StringReader a = new StringReader(child.OuterXml);
|
TextReader reader = new StringReader(child.OuterXml);
|
||||||
XmlDocument n = FromHTML((TextReader)a);
|
XmlDocument n = FromHTML(reader);
|
||||||
text += ProcessChild(n.ChildNodes);
|
text += ProcessChild(n.ChildNodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
XmlAttribute styleAttribute = node.Attributes["style"];
|
||||||
|
if(styleAttribute != null) {
|
||||||
|
if(styleAttribute.Value.Contains("bold")) {
|
||||||
|
text = "'''" + text + "'''";
|
||||||
|
}
|
||||||
|
if(styleAttribute.Value.Contains("italic")) {
|
||||||
|
text = "''" + text + "''";
|
||||||
|
}
|
||||||
|
if(styleAttribute.Value.Contains("underline")) {
|
||||||
|
text = "__" + text + "__";
|
||||||
|
}
|
||||||
|
}
|
||||||
result += marker + " " + text;
|
result += marker + " " + text;
|
||||||
if(!result.EndsWith("\n")) result += "\n";
|
if(!result.EndsWith("\n")) result += "\n";
|
||||||
foreach(XmlNode child in node.ChildNodes) {
|
foreach(XmlNode child in node.ChildNodes) {
|
||||||
|
@ -199,18 +211,18 @@ namespace ScrewTurn.Wiki {
|
||||||
break;
|
break;
|
||||||
case "b":
|
case "b":
|
||||||
case "strong":
|
case "strong":
|
||||||
result += "'''" + ProcessChild(node.ChildNodes) + "'''";
|
result += node.HasChildNodes ? "'''" + ProcessChild(node.ChildNodes) + "'''" : "";
|
||||||
break;
|
break;
|
||||||
case "strike":
|
case "strike":
|
||||||
case "s":
|
case "s":
|
||||||
result += "--" + ProcessChild(node.ChildNodes) + "--";
|
result += node.HasChildNodes ? "--" + ProcessChild(node.ChildNodes) + "--" : "";
|
||||||
break;
|
break;
|
||||||
case "em":
|
case "em":
|
||||||
case "i":
|
case "i":
|
||||||
result += "''" + ProcessChild(node.ChildNodes) + "''";
|
result += node.HasChildNodes ? "''" + ProcessChild(node.ChildNodes) + "''" : "";
|
||||||
break;
|
break;
|
||||||
case "u":
|
case "u":
|
||||||
result += "__" + ProcessChild(node.ChildNodes) + "__";
|
result += node.HasChildNodes ? "__" + ProcessChild(node.ChildNodes) + "__" : "";
|
||||||
break;
|
break;
|
||||||
case "h1":
|
case "h1":
|
||||||
if(node.HasChildNodes) {
|
if(node.HasChildNodes) {
|
||||||
|
@ -229,20 +241,25 @@ namespace ScrewTurn.Wiki {
|
||||||
result += "=====" + ProcessChild(node.ChildNodes) + "=====\n";
|
result += "=====" + ProcessChild(node.ChildNodes) + "=====\n";
|
||||||
break;
|
break;
|
||||||
case "pre":
|
case "pre":
|
||||||
result += "@@" + node.InnerText.ToString() + "@@";
|
result += node.HasChildNodes ? "@@" + node.InnerText.ToString() + "@@" : "";
|
||||||
break;
|
break;
|
||||||
case "code":
|
case "code":
|
||||||
result += "{{" + ProcessChild(node.ChildNodes) + "}}";
|
result += node.HasChildNodes ? "{{" + ProcessChild(node.ChildNodes) + "}}" : "";
|
||||||
break;
|
break;
|
||||||
case "hr":
|
case "hr":
|
||||||
case "hr /":
|
case "hr /":
|
||||||
result += "\n== ==\n" + ProcessChild(node.ChildNodes);
|
result += "\n== ==\n" + ProcessChild(node.ChildNodes);
|
||||||
break;
|
break;
|
||||||
case "span":
|
case "span":
|
||||||
if(node.Attributes.Count != 0) {
|
if(node.Attributes["style"] != null) {
|
||||||
XmlAttributeCollection attribute = node.Attributes;
|
if(node.Attributes["style"].Value.Replace(" ", "").Contains("font-weight:normal")) {
|
||||||
foreach(XmlAttribute attName in attribute) {
|
result += ProcessChild(node.ChildNodes);
|
||||||
if(attName.Value.ToString() == "italic") result += "''" + ProcessChild(node.ChildNodes) + "''";
|
}
|
||||||
|
}
|
||||||
|
if(node.Attributes.Count > 0) {
|
||||||
|
XmlAttributeCollection attributeCollection = node.Attributes;
|
||||||
|
foreach(XmlAttribute attribute in attributeCollection) {
|
||||||
|
if(attribute.Value == "italic") result += "''" + ProcessChild(node.ChildNodes) + "''";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -276,6 +293,9 @@ namespace ScrewTurn.Wiki {
|
||||||
else result += ProcessList(node.ChildNodes, "#");
|
else result += ProcessList(node.ChildNodes, "#");
|
||||||
break;
|
break;
|
||||||
case "ul":
|
case "ul":
|
||||||
|
if(node.PreviousSibling != null) {
|
||||||
|
result += "\n";
|
||||||
|
}
|
||||||
if(node.ParentNode != null) {
|
if(node.ParentNode != null) {
|
||||||
if(node.ParentNode.Name.ToLowerInvariant() != "td") result += ProcessList(node.ChildNodes, "*");
|
if(node.ParentNode.Name.ToLowerInvariant() != "td") result += ProcessList(node.ChildNodes, "*");
|
||||||
else result += node.OuterXml.ToString();
|
else result += node.OuterXml.ToString();
|
||||||
|
@ -289,26 +309,20 @@ namespace ScrewTurn.Wiki {
|
||||||
result += "<sub>" + ProcessChild(node.ChildNodes) + "</sub>";
|
result += "<sub>" + ProcessChild(node.ChildNodes) + "</sub>";
|
||||||
break;
|
break;
|
||||||
case "p":
|
case "p":
|
||||||
if(node.Attributes.Count != 0) {
|
if(node.Attributes["class"] != null && node.Attributes["class"].Value.Contains("imagedescription")) continue;
|
||||||
XmlAttributeCollection attribute = node.Attributes;
|
else result += ProcessChild(node.ChildNodes) + "\n\n";
|
||||||
foreach(XmlAttribute attName in attribute) {
|
|
||||||
if(attName.Value.ToString() == "imagedescription") result += "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else result += ProcessChild(node.ChildNodes) + "{BR}\n";
|
|
||||||
break;
|
break;
|
||||||
case "div":
|
case "div":
|
||||||
if(node.Attributes.Count != 0) {
|
if(node.Attributes["class"] != null) {
|
||||||
XmlAttributeCollection attribute = node.Attributes;
|
if(node.Attributes["class"].Value.Contains("box")) result += node.HasChildNodes ? "(((" + ProcessChild(node.ChildNodes) + ")))" : "";
|
||||||
foreach(XmlAttribute attName in attribute) {
|
if(node.Attributes["class"].Value.Contains("imageleft")) result += "[imageleft" + ProcessChildImage(node.ChildNodes) + "]\n";
|
||||||
if(attName.Value.ToString() == "box") result += "(((" + ProcessChild(node.ChildNodes) + ")))\n";
|
if(node.Attributes["class"].Value.Contains("imageright")) result += "[imageright" + ProcessChildImage(node.ChildNodes) + "]\n";
|
||||||
if(attName.Value.ToString() == "imageleft") result += "[imageleft" + ProcessChildImage(node.ChildNodes) + "]\n";
|
if(node.Attributes["class"].Value.Contains("image")) result += "[image" + ProcessChildImage(node.ChildNodes) + "]\n";
|
||||||
if(attName.Value.ToString() == "imageright") result += "[imageright" + ProcessChildImage(node.ChildNodes) + "]\n";
|
if(node.Attributes["class"].Value.Contains("indent")) result += ": " + ProcessChild(node.ChildNodes) + "\n";
|
||||||
if(attName.Value.ToString() == "image") result += "[image" + ProcessChildImage(node.ChildNodes) + "]\n";
|
|
||||||
if(attName.Value.ToString() == "indent") result += ": " + ProcessChild(node.ChildNodes) + "\n";
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
result += ProcessChild(node.ChildNodes) + "\n";
|
||||||
}
|
}
|
||||||
else result += (ProcessChild(node.ChildNodes) + "\n");
|
|
||||||
break;
|
break;
|
||||||
case "img":
|
case "img":
|
||||||
string description = "";
|
string description = "";
|
||||||
|
@ -351,7 +365,7 @@ namespace ScrewTurn.Wiki {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isInternalLink) {
|
if(isInternalLink) {
|
||||||
string[] splittedLink = link.Split('=');
|
string[] splittedLink = link.Split('=');
|
||||||
link = "c:" + splittedLink[1];
|
link = "c:" + splittedLink[1];
|
||||||
}
|
}
|
||||||
|
@ -377,7 +391,7 @@ namespace ScrewTurn.Wiki {
|
||||||
// setup SgmlReader
|
// setup SgmlReader
|
||||||
Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader();
|
Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader();
|
||||||
sgmlReader.DocType = "HTML";
|
sgmlReader.DocType = "HTML";
|
||||||
sgmlReader.WhitespaceHandling = WhitespaceHandling.All;
|
sgmlReader.WhitespaceHandling = WhitespaceHandling.None;
|
||||||
|
|
||||||
sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
|
sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
|
||||||
sgmlReader.InputStream = reader;
|
sgmlReader.InputStream = reader;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue