Auto-Indent html code


I would like to find a way to auto indent some html code view in a codemirror editor.
I Found these demos:

I didn’t test these solutions yet, I wonder if there is another more recent script that achieve this.
I use the last (5) version of CodeMirror.

Thanks in advance

PS : I would like to find a script that autoindent an html code each time I load the html code. I store thiscode in .json files so, no newline or tab characters must be stored, the indentation must be done in the editor by the fly…

Well, I did it on server side (not very skilled in JS to make it alone…)
Here’s the PHP function used (only took in account the tags I need on my site, table blockquote and other block tags have been omitted…)

function html_indent($content) {
    $pattern = array(
    $replace = array(
    $indented_content = preg_replace($pattern, $replace, $content);
    return $indented_content;