PluginProbe ʕ •ᴥ•ʔ
SiteOrigin CSS / 1.0.4
SiteOrigin CSS v1.0.4
1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0
so-css / lib / codemirror / addon / fold / markdown-fold.js
so-css / lib / codemirror / addon / fold Last commit date
brace-fold.js 11 years ago brace-fold.min.js 10 years ago comment-fold.js 11 years ago comment-fold.min.js 10 years ago foldcode.js 11 years ago foldcode.min.js 10 years ago foldgutter.css 11 years ago foldgutter.js 11 years ago foldgutter.min.js 10 years ago indent-fold.js 11 years ago indent-fold.min.js 10 years ago markdown-fold.js 11 years ago markdown-fold.min.js 10 years ago xml-fold.js 11 years ago xml-fold.min.js 10 years ago
markdown-fold.js
50 lines
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3
4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env
10 mod(CodeMirror);
11 })(function(CodeMirror) {
12 "use strict";
13
14 CodeMirror.registerHelper("fold", "markdown", function(cm, start) {
15 var maxDepth = 100;
16
17 function isHeader(lineNo) {
18 var tokentype = cm.getTokenTypeAt(CodeMirror.Pos(lineNo, 0));
19 return tokentype && /\bheader\b/.test(tokentype);
20 }
21
22 function headerLevel(lineNo, line, nextLine) {
23 var match = line && line.match(/^#+/);
24 if (match && isHeader(lineNo)) return match[0].length;
25 match = nextLine && nextLine.match(/^[=\-]+\s*$/);
26 if (match && isHeader(lineNo + 1)) return nextLine[0] == "=" ? 1 : 2;
27 return maxDepth;
28 }
29
30 var firstLine = cm.getLine(start.line), nextLine = cm.getLine(start.line + 1);
31 var level = headerLevel(start.line, firstLine, nextLine);
32 if (level === maxDepth) return undefined;
33
34 var lastLineNo = cm.lastLine();
35 var end = start.line, nextNextLine = cm.getLine(end + 2);
36 while (end < lastLineNo) {
37 if (headerLevel(end + 1, nextLine, nextNextLine) <= level) break;
38 ++end;
39 nextLine = nextNextLine;
40 nextNextLine = cm.getLine(end + 2);
41 }
42
43 return {
44 from: CodeMirror.Pos(start.line, firstLine.length),
45 to: CodeMirror.Pos(end, cm.getLine(end).length)
46 };
47 });
48
49 });
50