data-markdown.js 862 B

123456789101112131415161718192021222324252627
  1. // From https://gist.github.com/1343518
  2. // Modified by Hakim to handle markdown indented with tabs
  3. (function(){
  4. var slides = document.querySelectorAll('[data-markdown]');
  5. for( var i = 0, len = slides.length; i < len; i++ ) {
  6. var elem = slides[i];
  7. // strip leading whitespace so it isn't evaluated as code
  8. var text = elem.innerHTML;
  9. var leadingWs = text.match(/^\n?(\s*)/)[1].length,
  10. leadingTabs = text.match(/^\n?(\t*)/)[1].length;
  11. if( leadingTabs > 0 ) {
  12. text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' );
  13. }
  14. else if( leadingWs > 1 ) {
  15. text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' );
  16. }
  17. // here, have sum HTML
  18. elem.innerHTML = (new Showdown.converter()).makeHtml(text);
  19. }
  20. })();