How do I format HTML code in Code Mirror when the

2019-04-09 21:22发布

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.

标签: codemirror
1条回答
相关推荐>>
2楼-- · 2019-04-09 21:33

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

查看更多
登录 后发表回答