From 98986e1c5bc9181d38db62b2edf3997fc842cbc5 Mon Sep 17 00:00:00 2001 From: Jeroen van Warmerdam Date: Sun, 7 Dec 2014 15:10:15 +0100 Subject: [PATCH] Support code blocks; --- js/bootstrap-markdown.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/bootstrap-markdown.js b/js/bootstrap-markdown.js index a005351..f6c13fe 100644 --- a/js/bootstrap-markdown.js +++ b/js/bootstrap-markdown.js @@ -1164,11 +1164,19 @@ } // transform selection and set the cursor into chunked text - if (content.substr(selected.start-1,1) == '`' - && content.substr(selected.end,1) == '`' ) { + if (content.substr(selected.start-4,4) === '```\n' + && content.substr(selected.end,4) === '\n```') { + e.setSelection(selected.start-4, selected.end+4) + e.replaceSelection(chunk) + cursor = selected.start-4 + } else if (content.substr(selected.start-1,1) === '`' + && content.substr(selected.end,1) === '`') { e.setSelection(selected.start-1,selected.end+1) e.replaceSelection(chunk) cursor = selected.start-1 + } else if (content.indexOf('\n') > -1) { + e.replaceSelection('```\n'+chunk+'\n```') + cursor = selected.start+4 } else { e.replaceSelection('`'+chunk+'`') cursor = selected.start+1