editor.setOption('extraKeys', {
// bold
'Ctrl-B': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 2) === '**' && s.slice(-2) === '**';
cm.replaceSelection(t ? s.slice(2).slice(0, -2) : '**' + s + '**', 'around');
},
// italic
'Ctrl-I': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 1) === '_' && s.slice(-1) === '_';
cm.replaceSelection(t ? s.slice(1).slice(0, -1) : '_' + s + '_', 'around');
},
// code
'Ctrl-K': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 1) === '`' && s.slice(-1) === '`';
cm.replaceSelection(t ? s.slice(1).slice(0, -1) : '`' + s + '`', 'around');
},
// strike
'Delete': function(cm) {
var s = cm.getSelection(),
t = s.slice(0, 2) === '~~' && s.slice(-2) === '~~';
if (!s || s === '~~~~') return null;
cm.replaceSelection(t ? s.slice(2).slice(0, -2) : '~~' + s + '~~', 'around');
}
});
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.