diff --git a/Core-Tests/ReverseFormatterTests.cs b/Core-Tests/ReverseFormatterTests.cs
index bdb0eaa..7ccaf4d 100644
--- a/Core-Tests/ReverseFormatterTests.cs
+++ b/Core-Tests/ReverseFormatterTests.cs
@@ -27,22 +27,22 @@ namespace ScrewTurn.Wiki.Tests {
[TestCase("
text
", "(((text)))\r\n")]
[TestCase("text
", "\r\ntext\r\n")]
[TestCase("riga1\r\nriga2\r\nriga3","riga1\r\n'''riga2'''\r\nriga3")]
- [TestCase("- 1
- 2
- 3
- 3.1
- 3.2
- 3.2.1
- 3.3
- 4
", "# 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("- 1
- 2
", "# 1\r\n# 2\r\n\r\n")]
- [TestCase("", "* 1\r\n* 2\r\n\r\n")]
- [TestCase("- Punto 1
- Punto 2
- Punto 3
- Punto 4
- Punto 5
", "* Punto 1\r\n* Punto 2\r\n* Punto 3\r\n* Punto 4\r\n* Punto 5\r\n\r\n")]
- [TestCase("", "* it 1\r\n** 1.1\r\n** 1.2\r\n* it2\r\n\r\n")]
- [TestCase("", "* it 1\r\n*# 1.1\r\n*# 1.2\r\n* it2\r\n\r\n")]
- [TestCase("", "* '''1'''\r\n* 2\r\n\r\n")]
+ [TestCase("- 1
- 2
- 3
- 3.1
- 3.2
- 3.2.1
- 3.3
- 4
", "# 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")]
+ [TestCase("- 1
- 2
", "# 1\r\n# 2\r\n")]
+ [TestCase("", "* 1\r\n* 2\r\n")]
+ [TestCase("- Punto 1
- Punto 2
- Punto 3
- Punto 4
- Punto 5
", "* Punto 1\r\n* Punto 2\r\n* Punto 3\r\n* Punto 4\r\n* Punto 5\r\n")]
+ [TestCase("", "* it 1\r\n** 1.1\r\n** 1.2\r\n* it2\r\n")]
+ [TestCase("", "* it 1\r\n*# 1.1\r\n*# 1.2\r\n* it2\r\n")]
+ [TestCase("", "* '''1'''\r\n* 2\r\n")]
[TestCase("I'm an anchor", "[anchor|#init]I'm an anchor")]
[TestCase("This recall an anchor", "[#init|This recall an anchor]")]
[TestCase("BIG TITLE", "[^google.com|BIG TITLE]")]
[TestCase("try to esc tag", "try to esc tag")]
[TestCase("
leftalign
", "[imageleft|leftalign|{UP(MainPage)}image.png|^www.link.com]\r\n")]
- [TestCase("
", "[image|inlineimage|{UP(MainPage)}image.png]\r\n")]
- [TestCase("
", "[image|description|{UP(MainPage)}image.png|^www.google.it]\r\n")]
+ [TestCase("
", "[image||{UP(MainPage)}image.png]\r\n")]
+ [TestCase("
", "[image||{UP(MainPage)}image.png|^www.google.it]\r\n")]
[TestCase(" autoalign |
", "[imageauto|autoalign|{UP(MainPage)}image.png]\r\n")]
- [TestCase(" Auto align |
", "[imageauto|Auto align|{UP(MainPage)}image.png|www.link.com]\r\n")]
+ [TestCase(" Auto align |
", "[imageauto||{UP(MainPage)}image.png|www.link.com]\r\n")]
public void PlainTest(string input, string output) {
Assert.AreEqual(output, ReverseFormatter.ReverseFormat(input));
}
diff --git a/Core/Formatter.cs b/Core/Formatter.cs
index dac4818..62898f8 100644
--- a/Core/Formatter.cs
+++ b/Core/Formatter.cs
@@ -1207,7 +1207,7 @@ namespace ScrewTurn.Wiki {
/// The containing the text to process.
/// A value indicating whether the formatting is being done in bare-bones mode.
private static void ProcessLineBreaks(StringBuilder sb, bool bareBones) {
- if(bareBones || AreSingleLineBreaksToBeProcessed()) {
+ if(AreSingleLineBreaksToBeProcessed()) {
// Replace new-lines only when not enclosed in tags
Match match = NoSingleBr.Match(sb.ToString());
while(match.Success) {
@@ -1234,9 +1234,9 @@ namespace ScrewTurn.Wiki {
match = NoSingleBr.Match(sb.ToString(), match.Index + 1);
}
- sb.Replace("\n", "
");
+ sb.Replace("\n\n", "
");
- sb.Replace(SingleBrPlaceHolder, "\n");
+ sb.Replace(SingleBrPlaceHolder, "
");
}
diff --git a/Core/ReverseFormatter.cs b/Core/ReverseFormatter.cs
index 1d5424f..35269a4 100644
--- a/Core/ReverseFormatter.cs
+++ b/Core/ReverseFormatter.cs
@@ -15,6 +15,26 @@ namespace ScrewTurn.Wiki {
///
public static class ReverseFormatter {
+
+ ///
+ /// Searches the description.
+ ///
+ /// The nodes.
+ ///
+ private static string searchDescription (XmlNodeList nodes){
+ string description = "";
+ foreach (XmlNode n in nodes){
+ if(n.Name.ToLowerInvariant() == "p") {
+ foreach(XmlAttribute att in n.Attributes) {
+ if(att.Value.ToLowerInvariant().ToString() == "imagedescription")
+ description += processChild(n.ChildNodes);
+ }
+ }
+
+ }
+ return description;
+ }
+
///
/// Processes order or unorder lists and sublists.
///
@@ -28,6 +48,11 @@ namespace ScrewTurn.Wiki {
foreach(XmlNode node in nodes) {
if(node.Name.ToString() == "li") {
foreach(XmlNode child in node.ChildNodes) {
+ if(child.NodeType == XmlNodeType.Text) {
+ string ie = child.Value.ToString();
+ ie = ie.Replace("\r", string.Empty).Replace("\n", string.Empty);
+ child.Value = ie;
+ }
switch(child.Name.ToString()) {
case "ol":
result += processList(child.ChildNodes, marker + ol);
@@ -35,6 +60,11 @@ namespace ScrewTurn.Wiki {
case "ul":
result += processList(child.ChildNodes, marker + ul);
break;
+ case "br":
+ StringReader aa = new StringReader(child.OuterXml);
+ XmlDocument ne = FromHTML((TextReader)aa);
+ result += processChild(ne.ChildNodes);
+ break;
default:
StringReader a = new StringReader(child.OuterXml);
XmlDocument n = FromHTML((TextReader)a);
@@ -76,10 +106,12 @@ namespace ScrewTurn.Wiki {
string p = "";
string url = "";
string result = "";
+ bool hasDescription = false;
foreach(XmlNode node in nodes) {
if(node.Name.ToLowerInvariant() == "img")
image += processImage(node);
else if(node.Name.ToLowerInvariant() == "p") {
+ hasDescription = true;
p += "|" + processChild(node.ChildNodes) + "|";
}
else if(node.Name.ToLowerInvariant() == "a") {
@@ -99,6 +131,8 @@ namespace ScrewTurn.Wiki {
url = "|" + target + link;
}
}
+ if (!hasDescription)
+ p = "||";
result = p + image + url;
return result;
}
@@ -203,10 +237,10 @@ namespace ScrewTurn.Wiki {
result += processChild(node.ChildNodes);
break;
case "ol":
- result += processList(node.ChildNodes, "#") + "\r\n";
+ result += processList(node.ChildNodes, "#");
break;
case "ul":
- result += processList(node.ChildNodes, "*") + "\r\n";
+ result += processList(node.ChildNodes, "*");
break;
case "li":
result += processChild(node.ChildNodes);
@@ -257,7 +291,8 @@ namespace ScrewTurn.Wiki {
if(node.Attributes.Count != 0) {
foreach(XmlAttribute attName in node.Attributes) {
if(attName.Name.ToString() == "alt")
- description = attName.Value.ToString();
+ description = searchDescription(node.ParentNode.ChildNodes);
+ //description = attName.Value.ToString();
if(attName.Name.ToString() == "class")
hasClass = true;
}