Last active
February 25, 2018 20:48
-
-
Save lucainnocenti/40dfa3bfcbf5e885269d1d6061e710d6 to your computer and use it in GitHub Desktop.
Execute this code in the console to add the `Cmd-I` shortcut for markdown italic to all CodeMirror cells in the page. Tested on Google Colaboratory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var script = document.createElement('script'); | |
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
map = {'Cmd-I': function(cm) { | |
var s = cm.getSelection(), | |
t = s.slice(0, 1) === '*' && s.slice(-1) === '*'; | |
cm.replaceSelection(t ? s.slice(1, -1) : '*' + s + '*', 'around'); | |
}}; | |
$('.CodeMirror').each(function() { | |
$(this)[0].CodeMirror.addKeyMap(map); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment