Skip to content

Instantly share code, notes, and snippets.

@lucainnocenti
Last active February 25, 2018 20:48
Show Gist options
  • Save lucainnocenti/40dfa3bfcbf5e885269d1d6061e710d6 to your computer and use it in GitHub Desktop.
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.
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