Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit 9a96433

Browse files
authored
Correctly chooses the code tags to use
Fixes issue #1136, which showed that single backticks were being used for multiline code blocks when clicking the `code` button.
1 parent 7a8ba70 commit 9a96433

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

anchor/views/assets/js/editor.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,16 @@
106106
wrap('*', '*');
107107
},
108108
code: function() {
109-
wrap('`', '`');
109+
var wrapping = '`';
110+
var element = textarea[0];
111+
var start = element.selectionStart, end = element.selectionEnd;
112+
var value = element.value;
113+
114+
var selection = value.substring(start, end);
115+
if(/\n+.*/gm.test(selection)) {
116+
wrapping = '\n```\n';
117+
}
118+
wrap(wrapping, wrapping);
110119
},
111120
link: function() {
112121
var element = textarea[0];

0 commit comments

Comments
 (0)