Created
March 2, 2020 11:37
-
-
Save kaishuu0123/8a0beee28a68a525d0ab86e3f5e02543 to your computer and use it in GitHub Desktop.
code-block-folding.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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