5 <title>CodeMirror: Overlay Parser Demo</title>
6 <link rel="stylesheet" href="../lib/codemirror.css">
7 <script src="../lib/codemirror.js"></script>
8 <script src="../addon/mode/overlay.js"></script>
9 <script src="../mode/xml/xml.js"></script>
10 <link rel="stylesheet" href="../doc/docs.css">
12 <style type="text/css">
13 .CodeMirror {border: 1px solid black;}
14 .cm-mustache {color: #0ca;}
18 <h1>CodeMirror: Overlay Parser Demo</h1>
20 <form><textarea id="code" name="code">
24 <p>These are links to {{things}}:</p>
26 <li><a href="{{url}}">{{text}}</a></li>
33 CodeMirror.defineMode("mustache", function(config, parserConfig) {
34 var mustacheOverlay = {
35 token: function(stream, state) {
37 if (stream.match("{{")) {
38 while ((ch = stream.next()) != null)
39 if (ch == "}" && stream.next() == "}") break;
43 while (stream.next() != null && !stream.match("{{", false)) {}
47 return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay);
49 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {mode: "mustache"});
52 <p>Demonstration of a mode that parses HTML, highlighting
53 the <a href="http://mustache.github.com/">Mustache</a> templating
54 directives inside of it by using the code
55 in <a href="../addon/mode/overlay.js"><code>overlay.js</code></a>. View
56 source to see the 15 lines of code needed to accomplish this.</p>