2011-01-14 30 views
7

有沒有一種簡單的方法來重新格式化我的HTML從科莫多編輯或自動化過程對齊蒂?像Ctrl + KCtrl + D在Visual Studio中將是輝煌的。目前正在運行安裝了Tidy的Ubuntu。科莫多編輯 - HTML格式化整理

回答

8

如果你想一個解決方案,只是直線上升的作品,請執行以下操作:

彈出打開右側的工具箱面板 點擊齒輪,選擇新建宏,命名它你喜歡什麼。

這裏獲取宏代碼:

komodo edit macro

它包括從http://jsbeautifier.org/代碼和工程就像一個魅力...

接下來是設置了一個按鍵:

工具箱 選擇新的宏現在去鍵綁定

類型序列,它會告訴你,如果你輸入的序列是可用的。我使用Ctrl + /因爲它們彼此靠近。

乾杯!

+1

順便說一句,如果你想讓jsbeautifier的輸出看起來像Ctrl-k,Ctrl-d格式的Visual Studio,編輯宏並轉到'JavaScript'的情況。現在將indent_size更改爲4,將brace_style更改爲「end-expand」,並在末尾添加「good_stuff:true」。 – 2014-05-29 15:25:39

1

您可以設置一個命令來運行以用整潔的版本替換html的選擇。按Ctl + R打開命令窗口,並輸入tidy -utf8 -asxhtml -i以使用utf8編碼格式縮進xhtml的命令。檢查兩個框以「將選擇傳遞爲輸入」和「插入輸出」。您也可以在那裏指定自定義鍵綁定。

實例截圖http://grab.by/8C3t

7

found this formatting script (macro)和適應它爲我用最新的科莫多編輯(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 & 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(); 
} 
0

想要一個製表符而不是空格嗎?

除了@justquick說的,做一個查找/替換(Ctrl + h)。使用選項卡(\t,請確保正則表達式被選中)替換雙空格()以使html成爲標籤,而不是間隔。 Tidy默認使用兩個空格,如果您以不同方式配置Tidy,則必須更改查找。

0

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

2輸入在運行領域的整齊的命令行參數:

tidy -config tidy_config_html.txt 

3檢查所有的箱子

4輸入路徑要整理Start In字段

5單擊Key Binding選項卡

6使用按Ctrl + 1爲新密鑰序列

7按按Ctrl + A按Ctrl + 1

1

是TAOcode作出的答案是偉大的,但在科莫的較新版本的幾件事情已經改變,所以這裏是我更新的代碼,使之重新工作:

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