diff options
author | Hakim El Hattab <hakim.elhattab@gmail.com> | 2012-10-28 18:09:54 -0400 |
---|---|---|
committer | Hakim El Hattab <hakim.elhattab@gmail.com> | 2012-10-28 18:09:54 -0400 |
commit | e693717f2aa2d65f8f0cf6412a01084280fc2c9a (patch) | |
tree | b771830d6f4b81dd9f1fb2485161f0fb568aa318 /plugin/markdown/markdown.js | |
parent | 9da9726403ca25cfd7d6792987ce04b9299ebd2a (diff) | |
download | perl-software-in-gnu-guix-e693717f2aa2d65f8f0cf6412a01084280fc2c9a.tar perl-software-in-gnu-guix-e693717f2aa2d65f8f0cf6412a01084280fc2c9a.tar.gz |
update syntax highlight after editing (#210), move markdown and highlight scripts from lib to plugin
Diffstat (limited to 'plugin/markdown/markdown.js')
-rw-r--r-- | plugin/markdown/markdown.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js new file mode 100644 index 0000000..07ffd80 --- /dev/null +++ b/plugin/markdown/markdown.js @@ -0,0 +1,32 @@ +// From https://gist.github.com/1343518 +// Modified by Hakim to handle Markdown indented with tabs +(function(){ + + if( typeof Showdown === 'undefined' ) { + throw 'The reveal.js Markdown plugin requires Showdown to be loaded'; + } + + var sections = document.querySelectorAll( '[data-markdown]' ); + + 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 = ( template || section ).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' ); + } + + section.innerHTML = (new Showdown.converter()).makeHtml(text); + } + +})();
\ No newline at end of file |