Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format HTML code in Code Mirror when the value is set to it?

Tags:

codemirror

I am using the Code Mirror plugin to edit HTML source of a page. The HTML code is fetched from database and set as 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 proper format? Thanks in advance.

like image 872
Lakshmi Narayana Avatar asked Dec 26 '22 13:12

Lakshmi Narayana


1 Answers

There is a function called autoFormatRange

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

This fragment from the CodeMirror Group might 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

like image 155
Frank van Puffelen Avatar answered May 05 '23 23:05

Frank van Puffelen