1
0

runmode.html 1.9 KB

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