【问题标题】:Why doesn't my ace.js beautifier work as expected?为什么我的 ace.js 美化器没有按预期工作?
【发布时间】:2021-08-19 11:33:24
【问题描述】:

每当我调用 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>

如果需要更多信息,请告诉我。

【问题讨论】:

    标签: javascript ide editor ace-editor js-beautify


    【解决方案1】:

    我在尝试为我的编辑器实现自动完成时解决了这个问题。

    您可能还需要导入其他脚本以确保美化器正常工作。

    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ext-language_tools.js"></script>
    

    上面的脚本为我解决了这个问题。

    来源:Autocompletion in ACE editor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2017-12-26
      • 2023-04-01
      • 2019-08-28
      • 2014-10-18
      • 1970-01-01
      相关资源
      最近更新 更多