LaravelTest
49 строк · 1.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.registerHelper("fold", "markdown", function(cm, start) {15var maxDepth = 100;16
17function isHeader(lineNo) {18var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));19return tokentype && /\bheader\b/.test(tokentype);20}21
22function headerLevel(lineNo, line, nextLine) {23var match = line && line.match(/^#+/);24if (match && isHeader(lineNo)) return match[0].length;25match = nextLine && nextLine.match(/^[=\-]+\s*$/);26if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;27return maxDepth;28}29
30var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);31var level = headerLevel(start.line, firstLine, nextLine);32if (level === maxDepth) return undefined;33
34var lastLineNo = cm.lastLine();35var end = start.line, nextNextLine = cm.getLine(end + 2);36while (end < lastLineNo) {37if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;38++end;39nextLine = nextNextLine;40nextNextLine = cm.getLine(end + 2);41}42
43return {44from: CodeMirror.Pos(start.line, firstLine.length),45to: CodeMirror.Pos(end, cm.getLine(end).length)46};47});48
49});50