科莫多编辑 - HTML重新格式化/整洁

时间:2011-01-14 08:41:19

标签: html tidy htmltidy komodoedit

是否有一种简单的方法可以从Komodo Edit中重新格式化我的HTML或自动化针对Tidy的过程?像Visual Studio中的 Ctrl + K Ctrl + D 这样的东西会很精彩。目前运行Ubuntu并安装了Tidy。

6 个答案:

答案 0 :(得分:8)

如果您想要一个直接起作用的解决方案,请执行以下操作:

弹出右侧的工具箱面板 单击齿轮并选择“新建宏”,将其命名为您喜欢的名称。

在此处获取宏代码:

komodo edit macro

它包含来自http://jsbeautifier.org/的代码,就像魅力......

接下来是设置按键:

在工具箱中选择新的宏 现在转到键绑定

键入序列,它将告诉您键入的序列是否可用。我使用ctrl + /因为它们彼此靠近。

干杯!

答案 1 :(得分:7)

found this formatting script (macro)并将其改编为我个人使用的最新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();
}

答案 2 :(得分:1)

您可以设置一个命令来运行以用整齐的版本替换选择的html。按Ctl + R打开命令窗口并输入tidy -utf8 -asxhtml -i作为使用utf8编码格式化缩进xhtml的命令。选中两个框以“将选择作为输入”和“插入输出”。您还可以在那里指定自定义键绑定。

屏幕截图http://grab.by/8C3t

答案 3 :(得分:1)

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 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');
    ko.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();
}

最大的区别在于第5行:komodo.document.language变为komodo.view.language,第40行:Run_RunEncodedCommand变为ko.run.runEncodedCommand

答案 4 :(得分:0)

想要标签而不是空格吗?

除了@justquick所说的,还要进行查找/替换(Ctrl + h)。用选项卡(替换双空格(\t),确保勾选正则表达式)以使html选项卡而不是间距。 Tidy默认使用两个空格,如果您以不同方式配置Tidy,则必须更改查找。

答案 5 :(得分:0)

1转到工具箱=>添加=>新命令

2在“运行”字段中输入整齐的命令行参数:

tidy -config tidy_config_html.txt

3选中所有方框

4在Start In字段

中输入整理路径

5单击Key Binding标签

6使用 Ctrl + 1 作为新密钥序列

7按 Ctrl + A Ctrl + 1