CodeMirror Hotkeys for HTML Bold, Italic, …

editor.setOption('extraKeys', { // bold 'Ctrl-B': function(cm) { var s = cm.getSelection(), t = s.slice(0, 3) === '<b>' && s.slice(-4) === '</b>'; cm.replaceSelection(t ? s.slice(3).slice(0, -4) : '<b>' + s + '</b>', 'around'); }, // italic 'Ctrl-I': function(cm) { var s = cm.getSelection(), t = s.slice(0, 3) === '<i>' && s.slice(-4) === '</i>'; cm.replaceSelection(t ? s.slice(3).slice(0, -4) : '<i>' + s + '</i>', 'around'); }, // underline 'Ctrl-U': function(cm) { var s = cm.getSelection(), t = s.slice(0, 3) === '<u>' && s.slice(-4) === '</u>'; cm.replaceSelection(t ? s.slice(3).slice(0, -4) : '<u>' + s + '</u>', 'around'); }, // code 'Ctrl-K': function(cm) { var s = cm.getSelection(), t = s.slice(0, 6) === '<code>' && s.slice(-7) === '</code>'; cm.replaceSelection(t ? s.slice(6).slice(0, -7) : '<code>' + s + '</code>', 'around'); }, // strike 'Delete': function(cm) { var s = cm.getSelection(), t = s.slice(0, 5) === '<del>' && s.slice(-6) === '</del>'; if (!s || s === '<del></del>') return null; cm.replaceSelection(t ? s.slice(5).slice(0, -6) : '<del>' + s + '</del>', '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.