index.html 2.6 KB

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