javascript 如何在 Ace Editor 中格式化 XML 代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10753543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to format XML code in Ace Editor?
提问by Rohit Kumar
I am using ACE Editor to display xml content on my web page. I want to format the xml code in Editor.
我正在使用 ACE 编辑器在我的网页上显示 xml 内容。我想在编辑器中格式化 xml 代码。
Can Any one tell me how to do this ?
任何人都可以告诉我如何做到这一点?
采纳答案by David Hellsing
There are numerous modes included in the package and the Wiki at githubwill tell you how to implement it. Something like this:
包中包含多种模式,github 上的Wiki将告诉您如何实现它。像这样的东西:
var Mode = require('ace/mode/xml').Mode;
editor.getSession().setMode(new Mode());
回答by Jan Jongboom
XML Code formatting is not specified in Ace itself, as it's just an editor. Use any of the answers in this questionto prettify the code.
Ace 本身没有指定 XML 代码格式,因为它只是一个编辑器。使用此问题中的任何答案来美化代码。
var code = ace.getSession().getValue();
// prettify
ace.getSession().setValue(code);