CodeMirror HTML mode not working

CodeMirror parses HTML using the XML mode. To use it, the appropriate script must be included, same as with any other mode. Add its dependency in your markup: <script type=”text/javascript” src=”https://stackoverflow.com/site.com/js/libs/codemirror/mode/xml/xml.js”></script> and set the mode to xml: config = { mode : “xml”, // … }; In addition, you may want to configure the parser … Read more

Get CodeMirror instance

Another method I have found elsewhere is as follows: //Get a reference to the CodeMirror editor var editor = document.querySelector(‘.CodeMirror’).CodeMirror; This works well when you are creating the CodeMirror instance dynamically or replacing an existing DOM element with a CodeMirror instance.

CodeMirror 2 – Highlight only (no editor)

A much nicer and easier solution is to just set the readOnly property of the CodeMirror instance to true, like this: $(‘.code’).each(function() { var $this = $(this), $code = $this.html(); $this.empty(); var myCodeMirror = CodeMirror(this, { value: $code, mode: ‘javascript’, lineNumbers: !$this.is(‘.inline’), readOnly: true }); }); Just add the class .code to the tag containing … Read more

techhipbettruvabetnorabahisbahis forumueduseduseduseduseduseduseduedusedusedu