Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format code that is displayed in div

I'm building a Javascript based UI that generates code based on the UI. I got the code generation working. the code is saved in a string. I tried formatting it, indenting it, but I don't know how anymore. Is there a way to put out the code formatted?

For example if I have this string:

"<body><div><h1>Hi</h1></div></body>"

being output like this:

<body>
  <div>
    <h1>
      Hi
    </h1>
  </div>
</body>

right now I'm outputing like this:

$(".output").text(string);
like image 805
Niqql Avatar asked Apr 16 '26 22:04

Niqql


1 Answers

Take a look at code tag in html. Show your string wrapped by code tags

<code>your string</code>

Or use text area. https://jsfiddle.net/sureshatta/k1atgn6o/1/

If you are trying to achived the formatted output please have a look at Template literals

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

like image 61
Suresh Atta Avatar answered Apr 18 '26 10:04

Suresh Atta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!