PluginProbe ʕ •ᴥ•ʔ
SiteOrigin CSS / 1.1
SiteOrigin CSS v1.1
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 / brace-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 10 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
brace-fold.js
106 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", "brace", function(cm, start) {
15 var line = start.line, lineText = cm.getLine(line);
16 var startCh, tokenType;
17
18 function findOpening(openCh) {
19 for (var at = start.ch, pass = 0;;) {
20 var found = at <= 0 ? -1 : lineText.lastIndexOf(openCh, at - 1);
21 if (found == -1) {
22 if (pass == 1) break;
23 pass = 1;
24 at = lineText.length;
25 continue;
26 }
27 if (pass == 1 && found < start.ch) break;
28 tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
29 if (!/^(comment|string)/.test(tokenType)) return found + 1;
30 at = found - 1;
31 }
32 }
33
34 var startToken = "{", endToken = "}", startCh = findOpening("{");
35 if (startCh == null) {
36 startToken = "[", endToken = "]";
37 startCh = findOpening("[");
38 }
39
40 if (startCh == null) return;
41 var count = 1, lastLine = cm.lastLine(), end, endCh;
42 outer: for (var i = line; i <= lastLine; ++i) {
43 var text = cm.getLine(i), pos = i == line ? startCh : 0;
44 for (;;) {
45 var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
46 if (nextOpen < 0) nextOpen = text.length;
47 if (nextClose < 0) nextClose = text.length;
48 pos = Math.min(nextOpen, nextClose);
49 if (pos == text.length) break;
50 if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == tokenType) {
51 if (pos == nextOpen) ++count;
52 else if (!--count) { end = i; endCh = pos; break outer; }
53 }
54 ++pos;
55 }
56 }
57 if (end == null || line == end && endCh == startCh) return;
58 return {from: CodeMirror.Pos(line, startCh),
59 to: CodeMirror.Pos(end, endCh)};
60 });
61
62 CodeMirror.registerHelper("fold", "import", function(cm, start) {
63 function hasImport(line) {
64 if (line < cm.firstLine() || line > cm.lastLine()) return null;
65 var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
66 if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
67 if (start.type != "keyword" || start.string != "import") return null;
68 // Now find closing semicolon, return its position
69 for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
70 var text = cm.getLine(i), semi = text.indexOf(";");
71 if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
72 }
73 }
74
75 var start = start.line, has = hasImport(start), prev;
76 if (!has || hasImport(start - 1) || ((prev = hasImport(start - 2)) && prev.end.line == start - 1))
77 return null;
78 for (var end = has.end;;) {
79 var next = hasImport(end.line + 1);
80 if (next == null) break;
81 end = next.end;
82 }
83 return {from: cm.clipPos(CodeMirror.Pos(start, has.startCh + 1)), to: end};
84 });
85
86 CodeMirror.registerHelper("fold", "include", function(cm, start) {
87 function hasInclude(line) {
88 if (line < cm.firstLine() || line > cm.lastLine()) return null;
89 var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
90 if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
91 if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
92 }
93
94 var start = start.line, has = hasInclude(start);
95 if (has == null || hasInclude(start - 1) != null) return null;
96 for (var end = start;;) {
97 var next = hasInclude(end + 1);
98 if (next == null) break;
99 ++end;
100 }
101 return {from: CodeMirror.Pos(start, has + 1),
102 to: cm.clipPos(CodeMirror.Pos(end))};
103 });
104
105 });
106