markdown.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 notes = section.querySelector( 'aside.notes' );
  11. var template = section.querySelector( 'script' );
  12. // strip leading whitespace so it isn't evaluated as code
  13. var text = ( template || section ).innerHTML;
  14. var leadingWs = text.match(/^\n?(\s*)/)[1].length,
  15. leadingTabs = text.match(/^\n?(\t*)/)[1].length;
  16. if( leadingTabs > 0 ) {
  17. text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
  18. }
  19. else if( leadingWs > 1 ) {
  20. text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
  21. }
  22. section.innerHTML = (new Showdown.converter()).makeHtml(text);
  23. if( notes ) {
  24. section.appendChild( notes );
  25. }
  26. }
  27. })();