Closed yanggeorge closed 7 years ago
I have added a new Menu Item to treat JSON escape and un-escape. jn is very good. But I can not find how to set shortcut for my cmd. Can you help me ?
escape_json_string = function (str) { return str .replace(/[\\]/g, "\\\\") .replace(/[\"]/g, "\\\"") .replace(/[\/]/g, "\\/") .replace(/[\b]/g, "\\b") .replace(/[\f]/g, "\\f") .replace(/[\n]/g, "\\n") .replace(/[\r]/g, "\\r") .replace(/[\t]/g, "\\t"); }; unEscape_json_string = function (str) { return str .replace(/\\\\/g, "\\") .replace(/\\"/g, "\"") .replace(/\\\//g, "\/") .replace(/\\b/g, "\b") .replace(/\\f/g, "\f") .replace(/\\n/g, "\n") .replace(/\\r/g, "\r") .replace(/\\t/g, "\t"); }; var escape_unEscape_json_str = Editor.addMenu('JSON-Escape/UnEscape'); escape_unEscape_json_str.addItem({ text:'Escape', cmd:function(){ var un_escape_text = Editor.currentView.text; var escape_text = escape_json_string(un_escape_text); Editor.currentView.text = escape_text; } }); escape_unEscape_json_str.addItem({ text:'UnEscape', cmd: function () { var escape_text = Editor.currentView.text; var un_escape_text = unEscape_json_string(escape_text); Editor.currentView.text = un_escape_text; } });
You can find here an example
Excellent! Thanks!
I have added a new Menu Item to treat JSON escape and un-escape. jn is very good. But I can not find how to set shortcut for my cmd. Can you help me ?