Mercurial > hg > nodescore
diff www/p/lib/js/data-markdown.js @ 42:49c94f63b8b0
css for nexus 7 and associated files- archive m.a added - remove later
author | tzara <rc-web@kiben.net> |
---|---|
date | Tue, 04 Sep 2012 07:25:49 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/www/p/lib/js/data-markdown.js Tue Sep 04 07:25:49 2012 +0000 @@ -0,0 +1,27 @@ +// From https://gist.github.com/1343518 +// Modified by Hakim to handle markdown indented with tabs +(function(){ + + var slides = document.querySelectorAll('[data-markdown]'); + + for( var i = 0, len = slides.length; i < len; i++ ) { + var elem = slides[i]; + + // strip leading whitespace so it isn't evaluated as code + var text = elem.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' ); + } + + // here, have sum HTML + elem.innerHTML = (new Showdown.converter()).makeHtml(text); + } + +})(); \ No newline at end of file