Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);

        }
    }
});
like image 795
Yusaf Khaliq Avatar asked Nov 12 '22 11:11

Yusaf Khaliq


1 Answers

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"
});
like image 189
gkiely Avatar answered Nov 15 '22 07:11

gkiely