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.

100 lines
3.3 KiB

7 months ago
  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="https://codemirror.net/5"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></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/codemirror5">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>
  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>tags</code>, which can be used to add custom
  70. behavior for specific tags. When given, it should be an object
  71. mapping tag names (for example <code>script</code>) to arrays or
  72. three-element arrays. Those inner arrays indicate [attributeName,
  73. valueRegexp, <a href="../../doc/manual.html#option_mode">modeSpec</a>]
  74. specifications. For example, you could use <code>["type", /^foo$/,
  75. "foo"]</code> to map the attribute <code>type="foo"</code> to
  76. the <code>foo</code> mode. When the first two fields are null
  77. (<code>[null, null, "mode"]</code>), the given mode is used for
  78. any such tag that doesn't match any of the previously given
  79. attributes. For example:</p>
  80. <pre>var myModeSpec = {
  81. name: "htmlmixed",
  82. tags: {
  83. style: [["type", /^text\/(x-)?scss$/, "text/x-scss"],
  84. [null, null, "css"]],
  85. custom: [[null, null, "customMode"]]
  86. }
  87. }</pre>
  88. <p><strong>MIME types defined:</strong> <code>text/html</code>
  89. (redefined, only takes effect if you load this parser after the
  90. XML parser).</p>
  91. </article>