folding.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <!doctype html>
  2. <head>
  3. <title>CodeMirror: Code Folding Demo</title>
  4. <meta charset="utf-8"/>
  5. <link rel=stylesheet href="../doc/docs.css">
  6. <style>
  7. .some-css {
  8. color: red;
  9. line-height: 2;
  10. }
  11. </style>
  12. <link rel="stylesheet" href="../lib/codemirror.css">
  13. <link rel="stylesheet" href="../addon/fold/foldgutter.css" />
  14. <script src="../lib/codemirror.js"></script>
  15. <script src="../addon/fold/foldcode.js"></script>
  16. <script src="../addon/fold/foldgutter.js"></script>
  17. <script src="../addon/fold/brace-fold.js"></script>
  18. <script src="../addon/fold/xml-fold.js"></script>
  19. <script src="../addon/fold/indent-fold.js"></script>
  20. <script src="../addon/fold/markdown-fold.js"></script>
  21. <script src="../addon/fold/comment-fold.js"></script>
  22. <script src="../mode/javascript/javascript.js"></script>
  23. <script src="../mode/xml/xml.js"></script>
  24. <script src="../mode/css/css.js"></script>
  25. <script src="../mode/htmlmixed/htmlmixed.js"></script>
  26. <script src="../mode/python/python.js"></script>
  27. <script src="../mode/markdown/markdown.js"></script>
  28. <style type="text/css">
  29. .CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
  30. </style>
  31. </head>
  32. <body>
  33. <div id=nav>
  34. <a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../doc/logo.png"></a>
  35. <ul>
  36. <li><a href="../index.html">Home</a>
  37. <li><a href="../doc/manual.html">Manual</a>
  38. <li><a href="https://github.com/codemirror/codemirror">Code</a>
  39. </ul>
  40. <ul>
  41. <li><a class=active href="#">Code Folding</a>
  42. </ul>
  43. </div>
  44. <article>
  45. <h2>Code Folding Demo</h2>
  46. <form>
  47. <div style="max-width: 50em; margin-bottom: 1em">JavaScript:<br>
  48. <textarea id="code" name="code"></textarea></div>
  49. <div style="max-width: 50em; margin-bottom: 1em">HTML:<br>
  50. <textarea id="code-html" name="code-html"></textarea></div>
  51. <div style="max-width: 50em">Python:<br>
  52. <textarea id="code-python" name="code">
  53. def foo():
  54. do_some_stuff()
  55. here
  56. return None
  57. class Bar:
  58. __init__(self):
  59. if True:
  60. print("True")
  61. else:
  62. print("False")
  63. this_code_makes_no_sense():
  64. pass
  65. # A comment</textarea></div>
  66. <div style="max-width: 50em">Markdown:<br>
  67. <textarea id="code-markdown" name="code"></textarea></div>
  68. </form>
  69. <script id="script">
  70. /*
  71. * Demonstration of code folding
  72. */
  73. window.onload = function() {
  74. var te = document.getElementById("code");
  75. var sc = document.getElementById("script");
  76. te.value = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "");
  77. sc.innerHTML = "";
  78. var te_html = document.getElementById("code-html");
  79. te_html.value = document.documentElement.innerHTML;
  80. var te_python = document.getElementById("code-python");
  81. var te_markdown = document.getElementById("code-markdown");
  82. te_markdown.value = "# Foo\n## Bar\n\nblah blah\n\n## Baz\n\nblah blah\n\n# Quux\n\nblah blah\n"
  83. window.editor = CodeMirror.fromTextArea(te, {
  84. mode: "javascript",
  85. lineNumbers: true,
  86. lineWrapping: true,
  87. extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
  88. foldGutter: true,
  89. gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
  90. });
  91. editor.foldCode(CodeMirror.Pos(13, 0));
  92. window.editor_html = CodeMirror.fromTextArea(te_html, {
  93. mode: "text/html",
  94. lineNumbers: true,
  95. lineWrapping: true,
  96. extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
  97. foldGutter: true,
  98. gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
  99. });
  100. editor_html.foldCode(CodeMirror.Pos(0, 0));
  101. editor_html.foldCode(CodeMirror.Pos(34, 0));
  102. window.editor_python = CodeMirror.fromTextArea(te_python, {
  103. mode: "python",
  104. lineNumbers: true,
  105. extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
  106. foldGutter: true,
  107. gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
  108. });
  109. window.editor_markdown = CodeMirror.fromTextArea(te_markdown, {
  110. mode: "markdown",
  111. lineNumbers: true,
  112. lineWrapping: true,
  113. extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
  114. foldGutter: true,
  115. gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
  116. });
  117. };
  118. </script>
  119. </article>
  120. </body>