7

有没有一种简单的方法可以从 Komodo Edit 中重新格式化我的 HTML 或针对 Tidy 自动执行该过程?

CtrlVisual Studio 中的+ K, Ctrl+之类的东西D会很棒。我目前正在运行安装了 Tidy 的 Ubuntu。

4

5 回答 5

8

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

  • 弹出打开右侧的工具箱面板。
  • 单击齿轮并选择新建宏。把它命名为你喜欢的名字。

在此处获取宏代码:

Komodo 编辑宏 (404)

它包含来自http://jsbeautifier.org/的代码,工作起来就像一个魅力......

接下来是设置击键:

  • 在工具箱中选择您的新宏

  • 现在转到键绑定

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

于 2012-04-06T22:10:09.610 回答
7

找到了这个格式化脚本(宏),并使用最新的 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();
}
于 2011-02-21T16:30:27.337 回答
1

您可以设置一个命令来运行以将选定的 HTML 替换为整洁的版本。按Ctrl+R调出命令窗口并输入tidy -utf8 -asxhtml -i使用 UTF-8 编码格式化缩进 XHTML 的命令。

选中“将选择作为输入”和“插入输出”这两个框。您还可以在那里指定自定义键绑定。

示例截图: http: //grab.by/8C3t

于 2011-01-27T09:37:59.390 回答
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 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

于 2016-03-07T22:41:06.843 回答
0
  1. 转到菜单工具箱添加新命令

  2. 在 Run 字段中输入 Tidy 命令行参数:

     tidy -config tidy_config_html.txt
    
  3. 选中所有框

  4. Start In在字段中输入 Tidy 的路径

  5. 单击键绑定选项卡

  6. 使用Ctrl+1作为新的键序列

  7. Ctrl+ACtrl+1

于 2012-01-05T22:30:10.250 回答