Komodo Edit - HTML 重新格式化 / Tidy

发布于 2024-10-12 10:10:34 字数 183 浏览 3 评论 0原文

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

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

Is there a simple way to reformat my HTML from within Komodo Edit or to automate the process against Tidy?

Something like the Ctrl+K, Ctrl+D in Visual Studio would be brilliant. I am presently running Ubuntu with Tidy installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

莫相离 2024-10-19 10:10:34

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

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

在此处获取宏代码:

Komodo edit macro (404)

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

接下来是设置击键:

  • 在工具箱中选择新宏

  • 现在转到键绑定

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

If you want a solution that just straight up works, do the following:

  • Pop open the toolbox panel on the right.
  • Click on the gear and select New Macro. Name it what you like.

Get the macro code here:

Komodo edit macro (404)

It includes the code from http://jsbeautifier.org/ and works like a charm...

Next is to set up a keystroke:

  • Select your new macro in the toolbox

  • Now go to key bindings

    Type a sequence and it will tell you if the sequence you typed is available. I use Ctrl + / because they are near each other.

一城柳絮吹成雪 2024-10-19 10:10:34

找到了这个格式化脚本(宏)并将其改编为我个人使用最新的科莫多编辑(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();
}

I found this formatting script (macro) and adapted it for my personal use with the latest Komodo Edit (v6.1.0). It works well and I included the JavaScript formatting provided by a commentator, but I think it may only work with Komodo IDE. It's unimportant for my purposes.

Perhaps someone out there can find a universal improvement (using something like 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();
}
一抹微笑 2024-10-19 10:10:34

您可以设置要运行的命令,以将所选的 HTML 替换为整洁的版本。按 Ctrl + R 打开命令窗口,然后输入 tidy -utf8 -asxhtml -i 使用 UTF- 格式化缩进 XHTML 的命令8 编码。

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

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

You can set up a command to run to replace a selection of HTML with the tidy version. Press Ctrl + R to bring up the command window and enter tidy -utf8 -asxhtml -i for the command which formats indented XHTML using UTF-8 encoding.

Check the two boxes to "Pass selection as input" and "Insert output". You can also specify custom key bindings there.

Example screenshot: http://grab.by/8C3t

埋情葬爱 2024-10-19 10:10:34

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

The answer that TAOcode made is great, but in newer versions of Komodo a few things have changed, so here is my update to the code to make it work again:

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

The big differences are in line 5: komodo.document.language becomes komodo.view.language and line 40: Run_RunEncodedCommand becomes ko.run.runEncodedCommand

梦巷 2024-10-19 10:10:34
  1. 转到菜单工具箱添加新命令

  2. 在“运行”字段中输入 Tidy 命令行参数:

    <前><代码> tidy -config tidy_config_html.txt

  3. 选中所有框

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

  5. 单击Key Binding选项卡

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

  7. Ctrl + ACtrl + 1

  1. Go to menu ToolboxAddNew Command

  2. Enter the Tidy command line arguments in the Run field:

     tidy -config tidy_config_html.txt
    
  3. Check all the boxes

  4. Enter the path to Tidy in the Start In field

  5. Click the Key Binding tab

  6. Use Ctrl + 1 as the New Key Sequence

  7. Press Ctrl + A and Ctrl + 1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文