简体   繁体   中英

Why doesn't my ace.js beautifier work as expected?

Whenever I call beautifyCode(), the formatting of the code does changes, but it all comes on one line with varying spaces... Is this how it works or am I doing something wrong? Also, how can I solve this as an issue?

Code:

  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());

  }

Input:

<html>
<head>
 <title>Hello World</title>
</head>
<body>
  <form action="shyam.php">
    <input name="name" value="Shyam"/>
    <input type="submit"/>
  </form>
</body>
</html>

Output:

<html><head> <title>Hello World</title></head><body>  <form action="shyam.php">    <input name="name" value="Shyam"/>    <input type="submit"/>  </form></body></html>

Please let me know if any more information is needed.

I solved the issue while trying to implement auto-complete for my editor.

You might need to import other scripts as well to ensure that the beautifier works.

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

The above script solved the issue for me.

Source: Autocompletion in ACE editor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM