You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB

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