From 25efef8c4f1275db62925ed18bab7282a5b767b2 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Mon, 8 Oct 2012 09:15:36 -0400 Subject: wrap markdown in script text/template to fix parsing errors (closes #146 #155 #162) --- lib/js/data-markdown.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/js') diff --git a/lib/js/data-markdown.js b/lib/js/data-markdown.js index 84398a0..80f8eb0 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 -- cgit v1.2.3