Fixed {br} and <br /> in wikimarkup and visual, now work correctly

This commit is contained in:
Cristian Trapattoni 2011-02-28 14:48:31 +01:00
parent d68793daba
commit 4056860d9b
4 changed files with 33 additions and 14 deletions

View file

@ -23,7 +23,9 @@ namespace ScrewTurn.Wiki.Tests {
string output = Formatter.Format(Input, false, context, currentPage, out linkedPages, false);
// Ignore \r characters
Assert.AreEqual(ExpectedOutput.Replace("\r", ""), output.Replace("\r", ""), "Formatter output is different from expected output");
// Ignore \n characters
Assert.AreEqual(ExpectedOutput.Replace("\r\n", ""), output.Replace("\r\n", ""), "Formatter output is different from expected output");
}
[SetUp]
@ -92,11 +94,10 @@ second line@@
|}";
private const string ExpectedOutput =
@"<b>bold</b> <i>italic</i> <u>underlined</u> <strike>striked</strike>
<a class=""pagelink"" href=""page1.ashx"" title=""Page 1"">page1</a> <a class=""unknownlink"" href=""page2.ashx"" title=""page2"">title</a><br /><br /><pre>&#42; item 1
@"<b>bold</b> <i>italic</i> <u>underlined</u> <strike>striked</strike><br /><a class=""pagelink"" href=""page1.ashx"" title=""Page 1"">page1</a>
<a class=""unknownlink"" href=""page2.ashx"" title=""page2"">title</a><br /><br /><pre>&#42; item 1
&#42; item 2
second line</pre><br /><table><tr><td>cell</td><td>other cell</td></tr></table>
";
second line</pre><br /><table><tr><td>cell</td><td>other cell</td></tr></table>";
}

View file

@ -25,8 +25,9 @@ namespace ScrewTurn.Wiki.Tests {
[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>text</div>", "text\r\n")]
[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# {BR}\r\n\r\n\r\n{BR}\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\r\n\r\n")]
[TestCase("<ol><li>1</li><li>2</li></ol>", "# 1\r\n# 2\r\n\r\n")]
[TestCase("<ul><li>1</li><li>2</li></ul>", "* 1\r\n* 2\r\n\r\n")]
[TestCase("<html><ul><li>Punto 1</li><li>Punto 2</li><li>Punto 3</li><li>Punto 4</li><li>Punto 5</li></ul></html>", "* Punto 1\r\n* Punto 2\r\n* Punto 3\r\n* Punto 4\r\n* Punto 5\r\n\r\n")]

View file

@ -262,6 +262,22 @@ namespace ScrewTurn.Wiki {
match = ExtendedUpRegex.Match(sb.ToString(), end);
}
match = SpecialTagRegex.Match(sb.ToString());
while(match.Success) {
if(!IsNoWikied(match.Index, noWikiBegin, noWikiEnd, out end)) {
sb.Remove(match.Index, match.Length);
if(!forIndexing) {
switch(match.Value.Substring(1, match.Value.Length - 2).ToUpperInvariant()) {
case "BR":
sb.Insert(match.Index, "<br />");
break;
}
}
}
ComputeNoWiki(sb.ToString(), ref noWikiBegin, ref noWikiEnd);
match = SpecialTagRegex.Match(sb.ToString(), end);
}
if(!bareBones) {
NamespaceInfo ns = DetectNamespaceInfo(current);
match = SpecialTagRegex.Match(sb.ToString());
@ -293,9 +309,6 @@ namespace ScrewTurn.Wiki {
case "CLEAR":
sb.Insert(match.Index, @"<div style=""clear: both;""></div>");
break;
case "BR":
sb.Insert(match.Index, "<br />");
break;
case "TOP":
sb.Insert(match.Index, @"<a href=""#PageTop"">" + Exchanger.ResourceExchanger.GetResource("Top") + "</a>");
break;
@ -1196,17 +1209,19 @@ namespace ScrewTurn.Wiki {
private static void ProcessLineBreaks(StringBuilder sb, bool bareBones) {
if(bareBones || AreSingleLineBreaksToBeProcessed()) {
// Replace new-lines only when not enclosed in <nobr> tags
Match match = NoSingleBr.Match(sb.ToString());
while(match.Success) {
sb.Remove(match.Index, match.Length);
sb.Insert(match.Index, match.Value.Replace("\n", SingleBrPlaceHolder));
//sb.Insert(match.Index, match.Value.Replace("\n", "<br />"));
match = NoSingleBr.Match(sb.ToString(), match.Index + 1);
}
sb.Replace("\n", "<br />");
sb.Replace(SingleBrPlaceHolder, "\n");
//sb.Replace(SingleBrPlaceHolder, "<br />");
}
else {
// Replace new-lines only when not enclosed in <nobr> tags
@ -1215,12 +1230,14 @@ namespace ScrewTurn.Wiki {
while(match.Success) {
sb.Remove(match.Index, match.Length);
sb.Insert(match.Index, match.Value.Replace("\n", SingleBrPlaceHolder));
//sb.Insert(match.Index, match.Value.Replace("\n", "<br />"));
match = NoSingleBr.Match(sb.ToString(), match.Index + 1);
}
sb.Replace("\n\n", "<br /><br />");
sb.Replace("\n", "<br />");
sb.Replace(SingleBrPlaceHolder, "\n");
}
sb.Replace("<br>", "<br />");

View file

@ -176,7 +176,7 @@ namespace ScrewTurn.Wiki {
}
break;
case "br":
result += ("{BR}\r\n" + processChild(node.ChildNodes));
result += ("\r\n" + processChild(node.ChildNodes));
break;
case "table":
string image = "";
@ -244,7 +244,7 @@ namespace ScrewTurn.Wiki {
}
}
else
result += (processChild(node.ChildNodes) + "\r\n");
result += "\r\n" + (processChild(node.ChildNodes) + "\r\n");
break;
case "img":