5 <title>CodeMirror: Mode Runner Demo</title>
6 <link rel="stylesheet" href="../lib/codemirror.css">
7 <script src="../lib/codemirror.js"></script>
8 <script src="../addon/runmode/runmode.js"></script>
9 <script src="../mode/xml/xml.js"></script>
10 <link rel="stylesheet" href="../doc/docs.css">
13 <h1>CodeMirror: Mode Runner Demo</h1>
15 <textarea id="code" style="width: 90%; height: 7em; border: 1px solid black; padding: .2em .4em;">
17 <blah>Enter your xml here and press the button below to display
18 it as highlighted by the CodeMirror XML mode</blah>
19 <tag2 foo="2" bar="&quot;bar&quot;"/>
20 </foobar></textarea><br>
21 <button onclick="doHighlight();">Highlight!</button>
22 <pre id="output" class="cm-s-default"></pre>
25 function doHighlight() {
26 CodeMirror.runMode(document.getElementById("code").value, "application/xml",
27 document.getElementById("output"));
31 <p>Running a CodeMirror mode outside of the editor.
32 The <code>CodeMirror.runMode</code> function, defined
33 in <code><a href="../addon/runmode/runmode.js">lib/runmode.js</a></code> takes the following arguments:</p>
36 <dt><code>text (string)</code></dt>
37 <dd>The document to run through the highlighter.</dd>
38 <dt><code>mode (<a href="../doc/manual.html#option_mode">mode spec</a>)</code></dt>
39 <dd>The mode to use (must be loaded as normal).</dd>
40 <dt><code>output (function or DOM node)</code></dt>
41 <dd>If this is a function, it will be called for each token with
42 two arguments, the token's text and the token's style class (may
43 be <code>null</code> for unstyled tokens). If it is a DOM node,
44 the tokens will be converted to <code>span</code> elements as in
45 an editor, and inserted into the node
46 (through <code>innerHTML</code>).</dd>