ux/Showdown.js
[roojs1] / ux / Showdown.js
index e519c19..80b957c 100644 (file)
@@ -345,6 +345,9 @@ Roo.ux.Showdown.converter = function() {
     // These are all the transformations that form block-level
     // tags like paragraphs, headers, and list items.
     //
+            // code blocks first... so content does not get translated..
+            text = _DoCodeBlocks(text);
+            
             text = _DoHeaders(text);
     
             // Do Horizontal Rules:
@@ -354,7 +357,7 @@ Roo.ux.Showdown.converter = function() {
             text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
     
             text = _DoLists(text);
-            text = _DoCodeBlocks(text);
+    
             text = _DoBlockQuotes(text);
     
             // We already ran _HashHTMLBlocks() before, in Markdown(), but that
@@ -885,6 +888,28 @@ Roo.ux.Showdown.converter = function() {
             // attacklab: strip sentinel
             text = text.replace(/~0/,"");
     
+    
+      
+            text += '~0';
+          
+            text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, language, codeblock) {
+                    var end =  '\n';
+                
+                    // First parse the github code block
+                    codeblock =  _EncodeCode( codeblock); 
+                    codeblock =  _Detab(codeblock);
+                    codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
+                    codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
+                
+                    codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
+                
+                    return hashBlock(codeblock) ;
+            });
+          
+            // attacklab: strip sentinel
+            text = text.replace(/~0/, '');
+
+          
             return text;
     }
     
@@ -1237,7 +1262,7 @@ Roo.ux.Showdown.converter = function() {
             text = text.replace(/^(\t|[ ]{1,4})/gm,"~0"); // attacklab: g_tab_width
     
             // attacklab: clean up hack
-            text = text.replace(/~0/g,"")
+            text = text.replace(/~0/g,"");
     
             return text;
     }