Komodo Edit内からHTMLを再フォーマットする、またはTidyに対するプロセスを自動化する簡単な方法はありますか?
CtrlVisual Studioの+ K、Ctrl+のようなものはD素晴らしいでしょう。私は現在、TidyがインストールされたUbuntuを実行しています。
Komodo Edit内からHTMLを再フォーマットする、またはTidyに対するプロセスを自動化する簡単な方法はありますか?
CtrlVisual Studioの+ K、Ctrl+のようなものはD素晴らしいでしょう。私は現在、TidyがインストールされたUbuntuを実行しています。
まっすぐに機能するソリューションが必要な場合は、次の手順を実行します。
ここでマクロコードを取得します。
コモド編集マクロ(404)
http://jsbeautifier.org/からのコードが含まれており、魅力のように機能します...
次に、キーストロークを設定します。
ツールボックスで新しいマクロを選択します
次に、キーバインディングに移動します
シーケンスを入力すると、入力したシーケンスが使用可能かどうかがわかります。Ctrl+を使用する/のは、それらが互いに近いためです。
このフォーマットスクリプト(マクロ)を見つけて、最新のKomodo Edit(v6.1.0)で個人的に使用できるように調整しました。それはうまく機能し、コメンテーターによって提供されたJavaScriptフォーマットを含めましたが、KomodoIDEでのみ機能する可能性があると思います。それは私の目的にとって重要ではありません。
おそらく、そこにいる誰かが( 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をフォーマットするコマンドを入力します。
「選択を入力として渡す」と「出力を挿入する」の2つのチェックボックスをオンにします。そこでカスタムキーバインディングを指定することもできます。
スクリーンショットの例: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になります
メニューの[ツールボックス] → [追加] → [新しいコマンド]に移動します
[実行]フィールドにTidyコマンドライン引数を入力します。
tidy -config tidy_config_html.txt
すべてのチェックボックスをオンにします
Start In
フィールドにTidyへのパスを入力します
[キーバインド]タブをクリックします
Ctrl+1を新しいキーシーケンスとして使用します
Ctrl+AとCtrl+を押します1