Fixed <sub> and <sup> in formatter.cs, now don't see tag in visual editor
This commit is contained in:
parent
a15e48cff8
commit
c950307494
3 changed files with 56 additions and 19 deletions
|
@ -16,15 +16,15 @@ namespace ScrewTurn.Wiki.Tests {
|
|||
[TestCase("<em>text</em>", "''text''")]
|
||||
[TestCase("<u>text</u>", "__text__")]
|
||||
[TestCase("<s>text</s>", "--text--")]
|
||||
[TestCase("<h1>text</h1>", "==text==")]
|
||||
[TestCase("<h2>text</h2>", "===text===")]
|
||||
[TestCase("<h3>text</h3>", "====text====")]
|
||||
[TestCase("<h4>text</s>", "=====text=====")]
|
||||
[TestCase("<h1>text</h1>", "\r\n==text==\r\n")]
|
||||
[TestCase("<h2>text</h2>", "\r\n===text===\r\n")]
|
||||
[TestCase("<h3>text</h3>", "\r\n====text====\r\n")]
|
||||
[TestCase("<h4>text</s>", "\r\n=====text=====\r\n")]
|
||||
[TestCase("<sup>text</sup>", "<sup>text</sup>")]
|
||||
[TestCase("<sub>text</sub>", "<sub>text</sub>")]
|
||||
[TestCase("<pre><b>text</b></pre>", "@@text@@")]
|
||||
[TestCase("<code><b>text</b></code>", "{{'''text'''}}")]
|
||||
[TestCase("<div class=\"box\">text</div>", "(((text)))\r\n")]
|
||||
[TestCase("<div class=\"box\">text</div>", "\r\n(((text)))\r\n")]
|
||||
[TestCase("<div>text</div>", "\r\ntext\r\n")]
|
||||
[TestCase("<html>riga1\r\n<b>riga2</b>\r\nriga3</html>","riga1\r\n'''riga2'''\r\nriga3")]
|
||||
[TestCase("<html><ol><li>1</li><li>2</li><li>3<ol><li>3.1</li><li>3.2<ol><li>3.2.1</li></ol></li><li>3.3</li></ol></li><li>4<br /></li></ol><br /></html>", "# 1\r\n# 2\r\n# 3\r\n## 3.1\r\n## 3.2\r\n### 3.2.1\r\n## 3.3\r\n# 4\r\n\r\n\r\n")]
|
||||
|
@ -38,7 +38,7 @@ namespace ScrewTurn.Wiki.Tests {
|
|||
[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]\r\n")]
|
||||
[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("<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")]
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace ScrewTurn.Wiki {
|
|||
private static readonly Regex BoldRegex = new Regex(@"'''.+?'''", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex ItalicRegex = new Regex(@"''.+?''", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex BoldItalicRegex = new Regex(@"'''''.+?'''''", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex ApexRegex = new Regex(@"\<sup\>(.+?)\</sup\>", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex SubscribeRegex = new Regex(@"\<sub\>(.+?)\</sub\>",RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex UnderlinedRegex = new Regex(@"__.+?__", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex StrikedRegex = new Regex(@"(?<!(\<\!|\<))(\-\-(?!\>).+?\-\-)(?!(\>|\>))", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
private static readonly Regex CodeRegex = new Regex(@"\{\{.+?\}\}", RegexOptions.Compiled | RegexOptions.Singleline);
|
||||
|
@ -604,6 +606,32 @@ namespace ScrewTurn.Wiki {
|
|||
match = UnderlinedRegex.Match(sb.ToString(), end);
|
||||
}
|
||||
|
||||
match = ApexRegex.Match(sb.ToString());
|
||||
while(match.Success) {
|
||||
if(!IsNoWikied(match.Index, noWikiBegin, noWikiBegin, out end)) {
|
||||
sb.Remove(match.Index, match.Length);
|
||||
dummy = new StringBuilder("<sup>");
|
||||
dummy.Append(match.Value.Substring(11, match.Value.Length - 23));
|
||||
dummy.Append("</sup>");
|
||||
sb.Insert(match.Index, dummy.ToString());
|
||||
}
|
||||
ComputeNoWiki(sb.ToString(), ref noWikiBegin, ref noWikiEnd);
|
||||
match = ApexRegex.Match(sb.ToString(), end);
|
||||
}
|
||||
|
||||
match = SubscribeRegex.Match(sb.ToString());
|
||||
while(match.Success) {
|
||||
if(!IsNoWikied(match.Index, noWikiBegin, noWikiBegin, out end)) {
|
||||
sb.Remove(match.Index, match.Length);
|
||||
dummy = new StringBuilder("<sub>");
|
||||
dummy.Append(match.Value.Substring(11, match.Value.Length - 23));
|
||||
dummy.Append("</sub>");
|
||||
sb.Insert(match.Index, dummy.ToString());
|
||||
}
|
||||
ComputeNoWiki(sb.ToString(), ref noWikiBegin, ref noWikiEnd);
|
||||
match = SubscribeRegex.Match(sb.ToString(), end);
|
||||
}
|
||||
|
||||
match = StrikedRegex.Match(sb.ToString());
|
||||
while(match.Success) {
|
||||
if(!IsNoWikied(match.Index, noWikiBegin, noWikiEnd, out end)) {
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace ScrewTurn.Wiki {
|
|||
description += processChild(n.ChildNodes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
@ -137,6 +136,11 @@ namespace ScrewTurn.Wiki {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static string processCode(string text) {
|
||||
string result = "";
|
||||
result = text;
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// Processes the child.
|
||||
/// </summary>
|
||||
|
@ -149,7 +153,7 @@ namespace ScrewTurn.Wiki {
|
|||
if(node.NodeType == XmlNodeType.Text) {
|
||||
result += node.Value;
|
||||
}
|
||||
else if (node.NodeType != XmlNodeType.Whitespace){
|
||||
else if(node.NodeType != XmlNodeType.Whitespace) {
|
||||
switch(node.Name.ToLowerInvariant()) {
|
||||
case "html":
|
||||
result += processChild(node.ChildNodes);
|
||||
|
@ -158,6 +162,7 @@ namespace ScrewTurn.Wiki {
|
|||
case "strong":
|
||||
result += ("'''" + processChild(node.ChildNodes) + "'''");
|
||||
break;
|
||||
case "strike":
|
||||
case "s":
|
||||
result += ("--" + processChild(node.ChildNodes) + "--");
|
||||
break;
|
||||
|
@ -170,29 +175,32 @@ namespace ScrewTurn.Wiki {
|
|||
break;
|
||||
//break;
|
||||
case "h1":
|
||||
result += ("==" + processChild(node.ChildNodes) + "==");
|
||||
if(node.HasChildNodes)
|
||||
result += ("\r\n==" + processChild(node.ChildNodes) + "==\r\n");
|
||||
else
|
||||
result += ("\r\n== ==\r\n");
|
||||
break;
|
||||
//break;
|
||||
case "h2":
|
||||
result += ("===" + processChild(node.ChildNodes) + "===");
|
||||
result += ("\r\n===" + processChild(node.ChildNodes) + "===\r\n");
|
||||
break;
|
||||
//break;
|
||||
case "h3":
|
||||
result += ("====" + processChild(node.ChildNodes) + "====");
|
||||
result += ("\r\n====" + processChild(node.ChildNodes) + "====\r\n");
|
||||
break;
|
||||
//break;
|
||||
case "h4":
|
||||
result += ("=====" + processChild(node.ChildNodes) + "=====");
|
||||
result += ("\r\n=====" + processChild(node.ChildNodes) + "=====\r\n");
|
||||
break;
|
||||
case "pre":
|
||||
result += ("@@" + node.InnerText.ToString() + "@@");
|
||||
result += ("@@" + processCode(node.InnerText.ToString()) + "@@");
|
||||
break;
|
||||
case "code":
|
||||
result += ("{{" + processChild(node.ChildNodes) + "}}");
|
||||
break;
|
||||
case "hr":
|
||||
case "hr /":
|
||||
result += ("----" + processChild(node.ChildNodes));
|
||||
result += ("\r\n== ==\r\n" + processChild(node.ChildNodes));
|
||||
break;
|
||||
case "\t":
|
||||
result += (":" + processChild(node.ChildNodes));
|
||||
|
@ -266,15 +274,15 @@ namespace ScrewTurn.Wiki {
|
|||
XmlAttributeCollection attribute = node.Attributes;
|
||||
foreach(XmlAttribute attName in attribute) {
|
||||
if(attName.Value.ToString() == "box") {
|
||||
result += "(((" + processChild(node.ChildNodes) + ")))\r\n";
|
||||
result += "\r\n" + "(((" + processChild(node.ChildNodes) + ")))\r\n";
|
||||
}
|
||||
if(attName.Value.ToString() == "imageleft") {
|
||||
result += "[imageleft" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
result += "\r\n" + "[imageleft" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
}
|
||||
if(attName.Value.ToString() == "imageright")
|
||||
result += "[imageright" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
result += "\r\n" + "[imageright" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
if(attName.Value.ToString() == "imageauto")
|
||||
result += "[imageauto" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
result += "\r\n" + "[imageauto" + processChildImage(node.ChildNodes) + "]\r\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -352,6 +360,7 @@ namespace ScrewTurn.Wiki {
|
|||
break;
|
||||
}
|
||||
}
|
||||
else result += "";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue