Skip to content

Instantly share code, notes, and snippets.

@kaishuu0123
Created March 2, 2020 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaishuu0123/8a0beee28a68a525d0ab86e3f5e02543 to your computer and use it in GitHub Desktop.
Save kaishuu0123/8a0beee28a68a525d0ab86e3f5e02543 to your computer and use it in GitHub Desktop.
code-block-folding.js
/* eslint-disable */
(function(mod) {
mod(require("codemirror"));
})(function(CodeMirror) {
"use strict";
CodeMirror.registerHelper("fold", "codeBlock", function(cm, start) {
var firstLine = cm.getLine(start.line);
var spaceTo = firstLine.search(/^::: [a-z]+/);
if (spaceTo === -1) {
return;
}
var lastLineNo = cm.lastLine();
var end = start.line, nextLine = cm.getLine(start.line + 1);
while (end < lastLineNo) {
if (nextLine.search(/^:::$/) > -1) {
break;
}
++end;
nextLine = cm.getLine(end);
}
return {
from: CodeMirror.Pos(start.line, firstLine.length),
to: CodeMirror.Pos(end, cm.getLine(end).length)
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment