move a few things away in to-be-integrated/
[myslice.git] / to-be-integrated / third-party / codemirror-3.15 / demo / indentwrap.html
1 <!doctype html>
2 <html>
3   <head>
4     <meta charset="utf-8">
5     <title>CodeMirror: Indented wrapped line demo</title>
6     <link rel="stylesheet" href="../lib/codemirror.css">
7     <script src="../lib/codemirror.js"></script>
8     <script src="../mode/xml/xml.js"></script>
9     <link rel="stylesheet" href="../doc/docs.css">
10
11     <style type="text/css">
12       .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
13     </style>
14   </head>
15   <body>
16     <h1>CodeMirror: Indented wrapped line demo</h1>
17
18     <form><textarea id="code" name="code">
19 <!doctype html>
20 <body>
21   <h2 id="overview">Overview</h2>
22
23   <p>CodeMirror is a code-editor component that can be embedded in Web pages. The core library provides <em>only</em> the editor component, no accompanying buttons, auto-completion, or other IDE functionality. It does provide a rich API on top of which such functionality can be straightforwardly implemented. See the <a href="#addons">add-ons</a> included in the distribution, and the <a href="https://github.com/jagthedrummer/codemirror-ui">CodeMirror UI</a> project, for reusable implementations of extra features.</p>
24
25   <p>CodeMirror works with language-specific modes. Modes are JavaScript programs that help color (and optionally indent) text written in a given language. The distribution comes with a number of modes (see the <a href="../mode/"><code>mode/</code></a> directory), and it isn't hard to <a href="#modeapi">write new ones</a> for other languages.</p>
26 </body>
27 </textarea></form>
28
29     <p>This page uses a hack on top of the <code>"renderLine"</code>
30     event to make wrapped text line up with the base indentation of
31     the line.</p>
32
33     <script>
34       var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
35         lineNumbers: true,
36         lineWrapping: true,
37         mode: "text/html"
38       });
39       var charWidth = editor.defaultCharWidth(), basePadding = 4;
40       editor.on("renderLine", function(cm, line, elt) {
41         var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
42         elt.style.textIndent = "-" + off + "px";
43         elt.style.paddingLeft = (basePadding + off) + "px";
44       });
45       editor.refresh();
46     </script>
47
48   </body>
49 </html>