Search code examples
javascriptjqueryinternet-explorercodemirror

codemirror rendering code on single line


http://fiddle.jshell.net/tLth8/6/show/

in IE <9 the code is highlighted however new lines are ignored and the code is all on a single line like below How the code is rendered in ie<9

how can i get the lines to be rendered properly as in the source code like below

How the code should be rendered, (google chrome)

I have tried altering the css so lines are display:block; however there is no difference

what i have tried

.CodeMirror pre {
    display:block;
}
.CodeMirror-lines div{
    display:block;
}

jQuery source:

$("span.code, div.code").each(function () {

    var $this = $(this),
        isdiv = $this.is("div"),
        $code = (isdiv) ? $this.html().replace(/^(\r\n)|(\n)/, ''):$this.html(),
        $unescaped = (isdiv) ? $('<div/>').html($code).text() : $('<span/>').html($code).text();

    $this.empty();
    if (isdiv) {
        $this.css({
            "display": "block"
        });
        $this.after('<div class="clear"/>');
    }

    var editor = CodeMirror(this, {
        value: $unescaped,
        mode: (isdiv) ? "text/html" : "javascript",
        lineNumbers: (isdiv) ? true : false,
        readOnly: false
    });
    if (isdiv) {
        var linecount = editor.lineCount();
        for (j = 0; j < linecount; j++) {
            editor.indentLine(j);

        }
    }
});

Solution

  • I've always used a textarea tag to initialise codemirror. It's how it's done on the main site.

    Just tested it and it Works in ie8, ie9.

    var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                 mode: 'htmlmixed', 
                 tabMode: "indent"
    });