diff --git a/README.md b/README.md index 2d044f38bc1a5090c18cd05d67d329dcdd4d836a..25eb5b17a452a8dd0a1cce7e6eac620c1f6bc3c1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Markup heirarchy needs to be ``<div class="reveal"> <div class="slides"> <sectio It's possible to write your slides using Markdown. To enable Markdown simply add the ```data-markdown``` attribute to your ```<section>``` 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 <section data-markdown> diff --git a/index.html b/index.html index 420ef4d19f46e648926d67940bb50446853f1b49..a434ae4a56b1e3d16fbc85ae3f36adf02ac333ab 100644 --- a/index.html +++ b/index.html @@ -122,8 +122,8 @@ <section data-markdown> ## 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). <pre><code contenteditable style="margin-top: 20px;"><section data-markdown> ## Markdown support @@ -326,6 +326,6 @@ function linkify( selector ) { hljs.initHighlightingOnLoad(); } ); </script> - + </body> </html> \ No newline at end of file diff --git a/js/reveal.js b/js/reveal.js index 86af9c07c49adbf9447dd4b6ca5e0748d1ece733..541ea0d1ff6f6563f5898e2fbd07db1a26f61a95 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 3c5389b0216cd2de961a5dcf0c8f86590c121ddd..897247533ded7cae536abca9c81486a3e1853725 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); });