From 25efef8c4f1275db62925ed18bab7282a5b767b2 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 8 Oct 2012 09:15:36 -0400 Subject: [PATCH] wrap markdown in script text/template to fix parsing errors (closes #146 #155 #162) --- README.md | 12 +++++++----- index.html | 21 ++++++++++++--------- lib/js/data-markdown.js | 13 +++++++------ 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5ad4a8aa..8511f90a 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,17 @@ Markup heirarchy needs to be ``
``` elements and reveal.js will automatically load the JavaScript parser. +It's possible to write your slides using Markdown. To enable Markdown simply add the ```data-markdown``` attribute to your ```
``` elements and reveal.js will automatically load the JavaScript parser. Additionally, you should wrap the contents in a ```
``` diff --git a/index.html b/index.html index b5625c91..ce10815c 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,7 @@
+

Reveal.js

HTML Presentations Made Easy

@@ -129,17 +130,18 @@
- ## 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). +
@@ -314,6 +316,7 @@ function linkify( selector ) {

THE END

BY Hakim El Hattab / hakim.se

+
diff --git a/lib/js/data-markdown.js b/lib/js/data-markdown.js index 84398a0e..80f8eb01 100644 --- a/lib/js/data-markdown.js +++ b/lib/js/data-markdown.js @@ -2,13 +2,15 @@ // Modified by Hakim to handle Markdown indented with tabs (function(){ - var slides = document.querySelectorAll('[data-markdown]'); + var sections = document.querySelectorAll( '[data-markdown]' ); - for( var i = 0, len = slides.length; i < len; i++ ) { - var elem = slides[i]; + for( var i = 0, len = sections.length; i < len; i++ ) { + var section = sections[i]; + + var template = section.querySelector( 'script' ); // strip leading whitespace so it isn't evaluated as code - var text = elem.innerHTML; + var text = ( template || section ).innerHTML; var leadingWs = text.match(/^\n?(\s*)/)[1].length, leadingTabs = text.match(/^\n?(\t*)/)[1].length; @@ -20,8 +22,7 @@ text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' ); } - // here, have sum HTML - elem.innerHTML = (new Showdown.converter()).makeHtml(text); + section.innerHTML = (new Showdown.converter()).makeHtml(text); } })(); \ No newline at end of file