Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can codemirror be used on multiple textareas?

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.

like image 830
Jens Törnell Avatar asked Dec 18 '10 20:12

Jens Törnell


People also ask

How do you use CodeMirror lint?

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.

How do I use CodeMirror in textarea?

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.

Does GitHub use CodeMirror?

About. CodeMirror is open source under a permissive license (MIT). It is being developed on GitHub. Contributions are welcome.

How do I set up CodeMirror?

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.


1 Answers

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');
like image 57
alexn Avatar answered Sep 22 '22 15:09

alexn