From 0a440cee6c9a8e53aa0f95f8904bce5ff60dd6c5 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 31 Jul 2012 23:47:09 -0400 Subject: [PATCH] modified data-markdown to support markdown indented with tabs --- README.md | 2 +- index.html | 6 +++--- js/reveal.js | 2 +- lib/js/data-markdown.js | 22 ++++++++++++++-------- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2d044f3..25eb5b1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Markup heirarchy needs to be ``
``` elements and reveal.js will automatically load the JavaScript parser. -This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) which in turn uses [showdown](https://github.com/coreyti/showdown/). Syntax support seems limited judging by my initial tests, this may be due to conflicts with the reveal.js styles. Updates to come. +This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) which in turn uses [showdown](https://github.com/coreyti/showdown/). This is sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks). Updates to come. ```html
diff --git a/index.html b/index.html index 420ef4d..a434ae4 100644 --- a/index.html +++ b/index.html @@ -122,8 +122,8 @@
## Markdown support - For those of you who like that sort of thing. Instructions and a bit more info - available [here](https://github.com/hakimel/reveal.js#markdown). + For those of you who like that sort of thing. + Instructions and a bit more info available [here](https://github.com/hakimel/reveal.js#markdown).
<section data-markdown>
   ## Markdown support
@@ -326,6 +326,6 @@ function linkify( selector ) {
 				hljs.initHighlightingOnLoad(); 
 			} );
 		
-		
+
 	
 
\ No newline at end of file
diff --git a/js/reveal.js b/js/reveal.js
index 86af9c0..541ea0d 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1,5 +1,5 @@
 /*!
- * reveal.js 1.5 r6
+ * reveal.js 1.5 r7
  * http://lab.hakim.se/reveal-js
  * MIT licensed
  * 
diff --git a/lib/js/data-markdown.js b/lib/js/data-markdown.js
index 3c5389b..8972475 100644
--- a/lib/js/data-markdown.js
+++ b/lib/js/data-markdown.js
@@ -1,18 +1,24 @@
-// From https://gist.github.com/1343518, modified to not load showdown
+// From https://gist.github.com/1343518
+// Modified by Hakim to handle markdown indented with tabs
 (function(){
 
   [].forEach.call( document.querySelectorAll('[data-markdown]'), function  fn(elem){
     
     // strip leading whitespace so it isn't evaluated as code
-    var text      = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
-        // set indentation level so your markdown can be indented within your HTML
-        leadingws = text.match(/^\n?(\s*)/)[1].length,
-        regex     = new RegExp('\\n?\\s{' + leadingws + '}','g'),
-        md        = text.replace(regex,'\n'),
-        html      = (new Showdown.converter()).makeHtml(md);
+    var text = elem.innerHTML;
+    
+    var leadingWs = text.match(/^\n?(\s*)/)[1].length,
+        leadingTabs = text.match(/^\n?(\t*)/)[1].length;
+
+    if( leadingTabs > 0 ) {
+        text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
+    }
+    else if( leadingWs > 1 ) {
+        text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
+    }
 
     // here, have sum HTML
-    elem.innerHTML = html;
+    elem.innerHTML = (new Showdown.converter()).makeHtml(text);
 
   });
 
-- 
2.26.2