How to format HTML code in the Code Mirror window when a value is set on it?

I use the Code Mirror plugin to edit the page HTML page. HTML code is retrieved from the database and set as a value in Code Mirror. But after setting the value, it is displayed in the same format in which it was saved in the database. How can I display it in the correct format? Thank you in advance.

+4
source share
1 answer

There is a function called autoFormatRange

 editor.autoFormatRange(range.from, range.to); 

This snippet from CodeMirror Group may be what you need:

 function autoFormat() { var totalLines = editor.lineCount(); var totalChars = editor.getTextArea().value.length; editor.autoFormatRange({line:0, ch:0}, {line:totalLines, ch:totalChars}); } 

http://codemirror.net/2/demo/formatting.html

+10
source

All Articles