window.onload = function() {
var te = document.getElementById("code");
var sc = document.getElementById("script");
te.value = (sc.textContent || sc.innerText || sc.innerHTML).replace(/^\s*/, "");
var te_html = document.getElementById("code-html");
te_html.value = document.documentElement.innerHTML;
var te_python = document.getElementById("code-python");
var te_markdown = document.getElementById("code-markdown");
te_markdown.value = "# Foo\n## Bar\n\nblah blah\n\n## Baz\n\nblah blah\n\n# Quux\n\nblah blah\n"
var te_json = document.getElementById("code-json");
window.editor = CodeMirror.fromTextArea(te, {
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
editor.foldCode(CodeMirror.Pos(13, 0));
window.editor_json = CodeMirror.fromTextArea(te_json, {
mode: {name: "javascript", json: true},
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
var startToken = '{', endToken = '}';
var prevLine = window.editor_json.getLine(from.line);
if (prevLine.lastIndexOf('[') > prevLine.lastIndexOf('{')) {
startToken = '[', endToken = ']';
var internal = window.editor_json.getRange(from, to);
var toParse = startToken + internal + endToken;
var parsed = JSON.parse(toParse);
count = Object.keys(parsed).length;
return count ? `\u21A4${count}\u21A6` : '\u2194';
editor_json.foldCode(CodeMirror.Pos(5, 0));
window.editor_html = CodeMirror.fromTextArea(te_html, {
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
editor_html.foldCode(CodeMirror.Pos(0, 0));
editor_html.foldCode(CodeMirror.Pos(34, 0));
window.editor_python = CodeMirror.fromTextArea(te_python, {
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
window.editor_markdown = CodeMirror.fromTextArea(te_markdown, {
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]