"use strict"; $(function () { $("") .appendTo("body"); var opts = { lineNumbers: true, indentWithTabs: true, tabSize: 4, indentUnit: 4, viewportMargin: Infinity, lineWrapping: true, mode: { name: "htmlmixed", // text/html tags: { style: [ ["type", /^text\/(x-)?scss$/, "text/x-scss"], [null, null, "css"] ], script: [[null, null, "text/javascript"]], c: [[null, null, "text/x-perl"]] } } }; if ( window["CM_THEME"] ) opts.theme = window.CM_THEME; var opts_codeblock = JSON.parse(JSON.stringify(opts)); // deep copy opts_codeblock['readOnly'] = true; opts_codeblock['mode'] = 'text/x-perl'; $('textarea').each(function () { var myCodeMirror = CodeMirror.fromTextArea(this, opts); }); $('.codeblock:has(.codetext)').each(function () { var div = this; var text = $(div).text().trimEnd(); var myCodeMirror = CodeMirror( function(elt) { div.parentNode.replaceChild(elt, div); }, opts_codeblock); myCodeMirror.setValue(text); }); });