Can codemirror be used on more than one textarea? I use many textareas that are generated dynamically.
<script type="text/javascript">
var editor = CodeMirror.fromTextArea('code', {
height: "dynamic",
parserfile: "parsecss.js",
stylesheet: "codemirror/css/csscolors.css",
path: "codemirror/js/"
});
</script>
I would prefer setting a class on the textarea to connect it to codemirror. Is it possible? The Another way of solving it would be to set multiple IDs. The code above sets the ID "code" to connect to codemirror.
There's two ways to do this: Find a linter that you can run in the browser, run it on the content, and translate its output into the expected format. Write one from scratch, possibly using the syntax tree kept by the editor.
This could be used to, for example, replace a textarea with a real editor: var myCodeMirror = CodeMirror(function(elt) { myTextArea. parentNode. replaceChild(elt, myTextArea); }, {value: myTextArea.
About. CodeMirror is open source under a permissive license (MIT). It is being developed on GitHub. Contributions are welcome.
Download CodeMirror files. Download jQuery file. Inside the codemirror project folder create subfolders and name them js, css and plugin. The js folder will hold all the javascript files.
You can actually make multiple calls to CodeMirror.fromTextArea
to 'Codemirror-ify' multiple textareas.
If you want multiple textareas with the same options, wrap the Codemirror.fromTextArea
call in a function, like:
function editor(id)
{
CodeMirror.fromTextArea(id, {
height: "350px",
parserfile: "parsexml.js",
stylesheet: "css/xmlcolors.css",
path: "js/",
continuousScanning: 500,
lineNumbers: true
});
}
You can then apply it to your textareas like:
editor('code1');
editor('code2');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With