comparison 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
comparison
equal deleted inserted replaced
41:56767c69b7c4 42:49c94f63b8b0
1 // From https://gist.github.com/1343518
2 // Modified by Hakim to handle markdown indented with tabs
3 (function(){
4
5 var slides = document.querySelectorAll('[data-markdown]');
6
7 for( var i = 0, len = slides.length; i < len; i++ ) {
8 var elem = slides[i];
9
10 // strip leading whitespace so it isn't evaluated as code
11 var text = elem.innerHTML;
12
13 var leadingWs = text.match(/^\n?(\s*)/)[1].length,
14 leadingTabs = text.match(/^\n?(\t*)/)[1].length;
15
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
23 // here, have sum HTML
24 elem.innerHTML = (new Showdown.converter()).makeHtml(text);
25 }
26
27 })();