index.html 3.0 KB

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