aboutsummaryrefslogtreecommitdiff
path: root/lib/js
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2012-07-31 23:47:09 -0400
committerHakim El Hattab <hakim.elhattab@gmail.com>2012-07-31 23:47:09 -0400
commit0a440cee6c9a8e53aa0f95f8904bce5ff60dd6c5 (patch)
treeb101e27692a4f513819bfc051ca18657006eda69 /lib/js
parentff567372c09c5c6b2f527050bb9814179201bb5e (diff)
downloadperl-software-in-gnu-guix-0a440cee6c9a8e53aa0f95f8904bce5ff60dd6c5.tar
perl-software-in-gnu-guix-0a440cee6c9a8e53aa0f95f8904bce5ff60dd6c5.tar.gz
modified data-markdown to support markdown indented with tabs
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/data-markdown.js22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/js/data-markdown.js b/lib/js/data-markdown.js
index 3c5389b..8972475 100644
--- a/lib/js/data-markdown.js
+++ b/lib/js/data-markdown.js
@@ -1,18 +1,24 @@
-// From https://gist.github.com/1343518, modified to not load showdown
+// From https://gist.github.com/1343518
+// Modified by Hakim to handle markdown indented with tabs
(function(){
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
// strip leading whitespace so it isn't evaluated as code
- var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
- // set indentation level so your markdown can be indented within your HTML
- leadingws = text.match(/^\n?(\s*)/)[1].length,
- regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
- md = text.replace(regex,'\n'),
- html = (new Showdown.converter()).makeHtml(md);
+ 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 = html;
+ elem.innerHTML = (new Showdown.converter()).makeHtml(text);
});