问题描述
每当我调用 beautifyCode() 时,代码的格式都会发生变化,但它们都出现在一行中,但空格不同......这是它的工作原理还是我做错了什么?另外,我该如何解决这个问题?
代码:
var beautify = ace.require("ace/ext/beautify"); // get reference to extension
var editor = ace.edit("editor");
// This function is called to beautify the editor's code
function beautifyCode()
{
beautify.beautify(editor.getSession());
}
输入:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<form action="shyam.PHP">
<input name="name" value="Shyam"/>
<input type="submit"/>
</form>
</body>
</html>
输出:
<html><head> <title>Hello World</title></head><body> <form action="shyam.PHP"> <input name="name" value="Shyam"/> <input type="submit"/> </form></body></html>
如果需要更多信息,请告诉我。
解决方法
我在尝试为我的编辑器实现自动完成时解决了这个问题。
您可能还需要导入其他脚本以确保美化器正常工作。
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-language_tools.js"></script>
上面的脚本为我解决了这个问题。