You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2014/06/01 00:11:18 UTC

[3/3] git commit: CLEREZZA-829: Doubling a single enewline at the beginning of a
 to survive html serialization

CLEREZZA-829: Doubling a single enewline at the beginning of a <pre> to survive html serialization

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/251e2a9f
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/251e2a9f
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/251e2a9f

Branch: refs/heads/master
Commit: 251e2a9f0fab7becaa14dfe7e9a22ba31ceeabd4
Parents: 29c7809
Author: reto <re...@apache.org>
Authored: Sun Jun 1 00:09:17 2014 +0200
Committer: reto <re...@apache.org>
Committed: Sun Jun 1 00:09:17 2014 +0200

----------------------------------------------------------------------
 .../resources/tools/editor/styles/etch.css      |  4 +++
 .../editor/renderlets/TitledContentEtch.scala   | 31 ++++++++++++++++++--
 2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/251e2a9f/platform.editor/src/main/resources/META-INF/resources/tools/editor/styles/etch.css
----------------------------------------------------------------------
diff --git a/platform.editor/src/main/resources/META-INF/resources/tools/editor/styles/etch.css b/platform.editor/src/main/resources/META-INF/resources/tools/editor/styles/etch.css
index 3efe7ce..cd820ba 100644
--- a/platform.editor/src/main/resources/META-INF/resources/tools/editor/styles/etch.css
+++ b/platform.editor/src/main/resources/META-INF/resources/tools/editor/styles/etch.css
@@ -1,3 +1,7 @@
+body {
+    padding-top: 3cm;
+}
+
 /* === Editor === */
 .etch-editor-panel { display: none; padding: 5px; position: absolute; z-index: 10000;
     background: #dadada; border: 1px solid #bdbdbd; color: #535353; text-shadow: 0 1px 0 #fff;

http://git-wip-us.apache.org/repos/asf/clerezza/blob/251e2a9f/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentEtch.scala
----------------------------------------------------------------------
diff --git a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentEtch.scala b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentEtch.scala
index 99a4408..4f3e031 100644
--- a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentEtch.scala
+++ b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentEtch.scala
@@ -9,7 +9,8 @@ import org.apache.clerezza.platform.typerendering.scala._
 import org.apache.clerezza.rdf.ontologies.DISCOBITS
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;import scala.xml.Unparsed
-
+import scala.xml._
+import scala.xml.transform._
 
 
 /**
@@ -167,7 +168,7 @@ class TitledContentEtch extends SRenderlet {
               false
             );*/
             """
-        <html xmlns:disco="http://discobits.org/ontology#"> 
+        val html = <html xmlns:disco="http://discobits.org/ontology#"> 
           
             <head>
                 <link type="text/css" href="/style/style.css" rel="stylesheet" />
@@ -189,6 +190,32 @@ class TitledContentEtch extends SRenderlet {
             </script>
           </body>
         </html>
+        
+        //From: http://www.w3.org/TR/html5/syntax.html#syntax     
+        //"A single newline may be placed immediately after the start tag of pre 
+        //and textarea elements. If the element's contents are intended to 
+        //start with a newline, two consecutive newlines thus need to be 
+        //included by the author."
+        object preRule extends RewriteRule {
+          override def transform(n: Node): Seq[Node] = n match {
+            case e:Elem
+            	if(e.label == "pre") => e.child(0) match   {
+            		case t : Text =>
+            		  if (t.text(0) == '\n') {
+             				val newText = Text("\n"+t.text)
+     					    	e.copy(child = newText ++ e.child.tail)
+     					    } else {
+     					    	e
+     					    }
+     					  case _ => e
+     					}
+            case other => other
+          }
+        }
+        
+        object htmlLineBreaks extends RuleTransformer(preRule)
+
+        htmlLineBreaks(html)
       }
     }
   }