markdown.js 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. // From https://gist.github.com/1343518
  2. // Modified by Hakim to handle Markdown indented with tabs
  3. (function(){
  4. if( typeof Showdown === 'undefined' ) {
  5. throw 'The reveal.js Markdown plugin requires Showdown to be loaded';
  6. }
  7. var sections = document.querySelectorAll( '[data-markdown]' );
  8. for( var i = 0, len = sections.length; i < len; i++ ) {
  9. var section = sections[i];
  10. var template = section.querySelector( 'script' );
  11. // strip leading whitespace so it isn't evaluated as code
  12. var text = ( template || section ).innerHTML;
  13. var leadingWs = text.match(/^\n?(\s*)/)[1].length,
  14. leadingTabs = text.match(/^\n?(\t*)/)[1].length;
  15. if( leadingTabs > 0 ) {
  16. text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
  17. }
  18. else if( leadingWs > 1 ) {
  19. text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
  20. }
  21. section.innerHTML = (new Showdown.converter()).makeHtml(text);
  22. }
  23. })();