Dav*_*ave 7 html tidy htmltidy komodoedit
有没有一种简单的方法可以在Komodo Edit中重新格式化我的HTML,或者针对Tidy自动化这个过程?像Visual Studio中的Ctrl+ K,Ctrl+ 这样的东西D会很精彩.目前运行Ubuntu并安装了Tidy.
小智 8
如果您想要一个直接起作用的解决方案,请执行以下操作:
弹出右侧的工具箱面板单击齿轮并选择"新建宏",将其命名为您喜欢的名称.
在这里获取宏代码:
它包含来自http://jsbeautifier.org/的代码,就像一个魅力......
接下来是设置击键:
在工具箱中选择新宏现在转到键绑定
输入一个序列,它会告诉您输入的序列是否可用.我使用ctrl + /因为它们彼此靠近.
干杯!
小智 7
我找到了这个格式化脚本(宏),并将其改编为我个人使用的最新Komodo Edit(v6.1.0).它运行良好,我包括评论员提供的JavaScript格式,但我认为它可能只适用于Komodo IDE.这对我的目的来说并不重要.也许有人可以找到一个普遍的改进(使用类似html整洁的东西).
komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus(); }
var formatter;
var language = komodo.document.language;
switch (language) {
case 'Perl':
formatter = 'perltidy -i=2 -pt=2 -l=0';
break;
case 'XML':
case 'XUL':
case 'XLST':
formatter = 'tidy -q -xml -i -w 80';
break;
case 'HTML':
formatter = 'tidy -q -asxhtml -i -w 120';
break;
//case 'JavaScript':
// ko.views.manager.currentView.scimoz.selectAll();
// ko.views.manager.currentView.scimoz.replaceSel(js_beautify(ko.views.manager.currentView.scimoz.text, {indent_size: 2}));
// return null;
default:
alert("I don't know how to tidy " + language);
return null;
}
//save current cursor position
var currentPos = komodo.editor.currentPos;
try {
// Save the file. After the operation you can check what changes where made by
// File -> Show Unsaved Changes
komodo.doCommand('cmd_save');
// Group operations into a single undo
komodo.editor.beginUndoAction();
// Select entire buffer & pipe it into formatter.
komodo.doCommand('cmd_selectAll');
Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
// Restore cursor. It will be close to the where it started depending on how the text was modified.
komodo.editor.gotoPos(currentPos);
// On windows, when the output of a command is inserted into an edit buffer it has unix line ends.
komodo.doCommand('cmd_cleanLineEndings');
}
catch (e) {
alert(e);
}
finally {
// Must end undo action or may corrupt edit buffer
komodo.editor.endUndoAction();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16209 次 |
| 最近记录: |