Skip to content

Commit

Permalink
support for data-markdown (hakimel#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Jul 31, 2012
1 parent dc05ce1 commit 1985277
Show file tree
Hide file tree
Showing 4 changed files with 1,379 additions and 5 deletions.
22 changes: 18 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,23 @@ <h3 class="inverted">BY Hakim El Hattab / hakim.se</h3>
<script src="lib/js/head.min.js"></script>

<script>
// Load reveal.js as well as a classList polyfill if needed
head.js( !document.body.classList ? 'lib/js/classList.js' : null )
.js( 'js/reveal.js', function() {
// All scripts that should be loaded before initializing
var scripts = [];

// If the browser doesn't support classList, load a polyfill
if( !document.body.classList ) {
scripts.push( 'lib/js/classList.js' );
}

// Load markdown parser if there are slides defined using markdown
if( document.querySelector( '[data-markdown]' ) ) {
scripts.push( 'lib/js/showdown.js' );
scripts.push( 'lib/js/data-markdown.js' );
}

scripts.push( 'js/reveal.js' );

head.js.apply( null, scripts.concat([ function() {

// Parse the query string into a key/value object
var query = {};
Expand Down Expand Up @@ -290,7 +304,7 @@ <h3 class="inverted">BY Hakim El Hattab / hakim.se</h3>
transition: query.transition || 'default' // default/cube/page/concave/linear(2d)
});

} );
}]));

// Load highlight.js for syntax highlighting of code samples
head.js( 'lib/js/highlight.js', function() {
Expand Down
2 changes: 1 addition & 1 deletion js/reveal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* reveal.js 1.5 r3
* reveal.js 1.5 r4
* http://lab.hakim.se/reveal-js
* MIT licensed
*
Expand Down
19 changes: 19 additions & 0 deletions lib/js/data-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// From https://gist.github.com/1343518, modified to not load showdown
(function boom(){

[].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);

// here, have sum HTML
elem.innerHTML = html;

});

}());
Loading

0 comments on commit 1985277

Please sign in to comment.