index.html 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!doctype html>
  2. <title>CodeMirror: HTML mixed mode</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="../xml/xml.js"></script>
  8. <script src="../javascript/javascript.js"></script>
  9. <script src="../css/css.js"></script>
  10. <script src="../vbscript/vbscript.js"></script>
  11. <script src="htmlmixed.js"></script>
  12. <style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
  13. <div id=nav>
  14. <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
  15. <ul>
  16. <li><a href="../../index.html">Home</a>
  17. <li><a href="../../doc/manual.html">Manual</a>
  18. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  19. </ul>
  20. <ul>
  21. <li><a href="../index.html">Language modes</a>
  22. <li><a class=active href="#">HTML mixed</a>
  23. </ul>
  24. </div>
  25. <article>
  26. <h2>HTML mixed mode</h2>
  27. <form><textarea id="code" name="code">
  28. <html style="color: green">
  29. <!-- this is a comment -->
  30. <head>
  31. <title>Mixed HTML Example</title>
  32. <style type="text/css">
  33. h1 {font-family: comic sans; color: #f0f;}
  34. div {background: yellow !important;}
  35. body {
  36. max-width: 50em;
  37. margin: 1em 2em 1em 5em;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <h1>Mixed HTML Example</h1>
  43. <script>
  44. function jsFunc(arg1, arg2) {
  45. if (arg1 && arg2) document.body.innerHTML = "achoo";
  46. }
  47. </script>
  48. </body>
  49. </html>
  50. </textarea></form>
  51. <script>
  52. // Define an extended mixed-mode that understands vbscript and
  53. // leaves mustache/handlebars embedded templates in html mode
  54. var mixedMode = {
  55. name: "htmlmixed",
  56. scriptTypes: [{matches: /\/x-handlebars-template|\/x-mustache/i,
  57. mode: null},
  58. {matches: /(text|application)\/(x-)?vb(a|script)/i,
  59. mode: "vbscript"}]
  60. };
  61. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: mixedMode});
  62. </script>
  63. <p>The HTML mixed mode depends on the XML, JavaScript, and CSS modes.</p>
  64. <p>It takes an optional mode configuration
  65. option, <code>scriptTypes</code>, which can be used to add custom
  66. behavior for specific <code>&lt;script type="..."></code> tags. If
  67. given, it should hold an array of <code>{matches, mode}</code>
  68. objects, where <code>matches</code> is a string or regexp that
  69. matches the script type, and <code>mode</code> is
  70. either <code>null</code>, for script types that should stay in
  71. HTML mode, or a <a href="../../doc/manual.html#option_mode">mode
  72. spec</a> corresponding to the mode that should be used for the
  73. script.</p>
  74. <p><strong>MIME types defined:</strong> <code>text/html</code>
  75. (redefined, only takes effect if you load this parser after the
  76. XML parser).</p>
  77. </article>