2012-05-25 59 views
3

我正在使用ACE編輯器在我的網頁上顯示xml內容。我想在編輯器中格式化xml代碼。如何在Ace Editor中格式化XML代碼?

Can任何人都可以告訴我該怎麼做?

+0

我已經應用了editor.session.setFoldStyle(「markbeginend」); –

回答

3

包裝中包含多種模式,Wiki at github會告訴您如何實施它。這樣的事情:

var Mode = require('ace/mode/xml').Mode; 
editor.getSession().setMode(new Mode()); 
+0

我已經使用XML模式,但我想要的東西,可以格式化XML編輯器中顯示的內容。在eclipse中可以和「Ctrl + shift + F」相同的東西來格式化代碼。 –

14

在Ace本身沒有指定XML代碼格式,因爲它只是一個編輯器。使用this question中的任何答案來優化代碼。

var code = ace.getSession().getValue(); 
// prettify 
ace.getSession().setValue(code);