有没有一种简单的方法可以从 Komodo Edit 中重新格式化我的 HTML 或针对 Tidy 自动执行该过程?
CtrlVisual Studio 中的+ K, Ctrl+之类的东西D会很棒。我目前正在运行安装了 Tidy 的 Ubuntu。
有没有一种简单的方法可以从 Komodo Edit 中重新格式化我的 HTML 或针对 Tidy 自动执行该过程?
CtrlVisual Studio 中的+ K, Ctrl+之类的东西D会很棒。我目前正在运行安装了 Tidy 的 Ubuntu。
如果您想要一个直接有效的解决方案,请执行以下操作:
在此处获取宏代码:
Komodo 编辑宏 (404)
它包含来自http://jsbeautifier.org/的代码,工作起来就像一个魅力......
接下来是设置击键:
在工具箱中选择您的新宏
现在转到键绑定
键入一个序列,它会告诉您您键入的序列是否可用。我使用Ctrl+/因为它们彼此靠近。
我找到了这个格式化脚本(宏),并使用最新的 Komodo Edit (v6.1.0) 对其进行了调整以供我个人使用。它运行良好,我包含了评论员提供的 JavaScript 格式,但我认为它可能只适用于 Komodo IDE。这对我的目的来说并不重要。
也许有人可以找到一个普遍的改进(使用HTML Tidy之类的东西)。
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 and 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 we may corrupt edit buffer
komodo.editor.endUndoAction();
}
您可以设置一个命令来运行以将选定的 HTML 替换为整洁的版本。按Ctrl+R调出命令窗口并输入tidy -utf8 -asxhtml -i
使用 UTF-8 编码格式化缩进 XHTML 的命令。
选中“将选择作为输入”和“插入输出”这两个框。您还可以在那里指定自定义键绑定。
示例截图: http: //grab.by/8C3t
TAOcode 给出的答案很棒,但是在较新版本的 Komodo 中,一些事情发生了变化,所以这是我对代码的更新以使其再次工作:
komodo.assertMacroVersion(3);
if (komodo.view) {
komodo.view.setFocus();
}
var formatter;
var language = komodo.view.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 500';
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 the 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 the entire buffer and pipe it into the formatter.
komodo.doCommand('cmd_selectAll');
ko.run.runEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
// Restore the 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();
}
最大的区别在于第 5 行:komodo.document.language 变为 komodo.view.language 和第 40 行:Run_RunEncodedCommand 变为 ko.run.runEncodedCommand
转到菜单工具箱→添加→新命令
在 Run 字段中输入 Tidy 命令行参数:
tidy -config tidy_config_html.txt
选中所有框
Start In
在字段中输入 Tidy 的路径
单击键绑定选项卡
使用Ctrl+1作为新的键序列
按Ctrl+A和Ctrl+1