runmode.html 2.2 KB

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