サクラエディタ用の自作マクロ 参考:サクラエディタマクロ
| ExecCommand | HTML Escape | List | Table | JsDoc |
// V8で実行 Editor.ExecCommand("cmd /k E:\\Documents\\js\\v8\\d8.exe \"$F\"", 0);
// 選択範囲をHTMLエスケープ var s = Editor.GetSelectedString(0); if (s) { Editor.InsText( s .replace(/&/g,"&") .replace(/</g,"<") .replace(/>/g,">") .replace(/"/g, '"') .replace(/'/g, "'") ); }
// a <li>a</li> // b -> <li>b</li> // c <li>c</li> var s = Editor.GetSelectedString(0); if (!s) { Editor.SelectAll(); s = Editor.GetSelectedString(0); } s = s.replace(/[\r\n]+$/, ''); s = '<li>'+ s.replace(/\r\n/g, '</li>\r\n<li>') +'</li>\r\n'; Editor.InsText(s);
// <table> 作成支援 var s = Editor.GetSelectedString(0); if (!s) { Editor.SelectAll(); s = Editor.GetSelectedString(0); } s = s.replace(/[\r\n]+$/,''); s = '<table>\r\n<tr><td>' + s.replace(/ +/g,'</td><td>').replace(/\r\n/g,'</td></tr>\r\n<tr><td>') + '</td></tr>\r\n</table>\r\n'; Editor.InsText(s);
// function のある行で実行 // // /** // * // * @param {object} foo // * @param {object} bar // */ // function barbar(foo, bar) var s = Editor.GetLineStr(0); Editor.GoLineTop(1); if (s.indexOf('function') > -1) { s = s.replace(/([\t ]*)function[^(]*\((.*)\)[^)]*/g, function(src, indent, args) { var r = indent +'/**\n'; r += indent +' * \n'; for (var i = 0, a = args.split(','), l = a.length; i < l; i++) { r += indent +' * @param {object} '+ a[i].replace(/^ +| +$/g, '') +'\n'; } r += indent +' *\/\n'; return r; }); } else { s = '/**\n * \n */\n'; } Editor.InsText(s);