Skip to content

Commit bc019d5

Browse files
committed
add editor libs
1 parent f6c223f commit bc019d5

File tree

328 files changed

+58649
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+58649
-0
lines changed

static/js/plugins/editormd/lib/codemirror/AUTHORS

Lines changed: 436 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2014 by Marijn Haverbeke <marijnh@gmail.com> and others
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# CodeMirror
2+
[![Build Status](https://travis-ci.org/codemirror/CodeMirror.svg)](https://travis-ci.org/codemirror/CodeMirror)
3+
[![NPM version](https://img.shields.io/npm/v/codemirror.svg)](https://www.npmjs.org/package/codemirror)
4+
[Funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png)](https://marijnhaverbeke.nl/fund/)
5+
6+
CodeMirror is a JavaScript component that provides a code editor in
7+
the browser. When a mode is available for the language you are coding
8+
in, it will color your code, and optionally help with indentation.
9+
10+
The project page is http://codemirror.net
11+
The manual is at http://codemirror.net/doc/manual.html
12+
The contributing guidelines are in [CONTRIBUTING.md](https://github.com/codemirror/CodeMirror/blob/master/CONTRIBUTING.md)
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
var noOptions = {};
15+
var nonWS = /[^\s\u00a0]/;
16+
var Pos = CodeMirror.Pos;
17+
18+
function firstNonWS(str) {
19+
var found = str.search(nonWS);
20+
return found == -1 ? 0 : found;
21+
}
22+
23+
CodeMirror.commands.toggleComment = function(cm) {
24+
var minLine = Infinity, ranges = cm.listSelections(), mode = null;
25+
for (var i = ranges.length - 1; i >= 0; i--) {
26+
var from = ranges[i].from(), to = ranges[i].to();
27+
if (from.line >= minLine) continue;
28+
if (to.line >= minLine) to = Pos(minLine, 0);
29+
minLine = from.line;
30+
if (mode == null) {
31+
if (cm.uncomment(from, to)) mode = "un";
32+
else { cm.lineComment(from, to); mode = "line"; }
33+
} else if (mode == "un") {
34+
cm.uncomment(from, to);
35+
} else {
36+
cm.lineComment(from, to);
37+
}
38+
}
39+
};
40+
41+
CodeMirror.defineExtension("lineComment", function(from, to, options) {
42+
if (!options) options = noOptions;
43+
var self = this, mode = self.getModeAt(from);
44+
var commentString = options.lineComment || mode.lineComment;
45+
if (!commentString) {
46+
if (options.blockCommentStart || mode.blockCommentStart) {
47+
options.fullLines = true;
48+
self.blockComment(from, to, options);
49+
}
50+
return;
51+
}
52+
var firstLine = self.getLine(from.line);
53+
if (firstLine == null) return;
54+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line + 1 : to.line, self.lastLine() + 1);
55+
var pad = options.padding == null ? " " : options.padding;
56+
var blankLines = options.commentBlankLines || from.line == to.line;
57+
58+
self.operation(function() {
59+
if (options.indent) {
60+
var baseString = firstLine.slice(0, firstNonWS(firstLine));
61+
for (var i = from.line; i < end; ++i) {
62+
var line = self.getLine(i), cut = baseString.length;
63+
if (!blankLines && !nonWS.test(line)) continue;
64+
if (line.slice(0, cut) != baseString) cut = firstNonWS(line);
65+
self.replaceRange(baseString + commentString + pad, Pos(i, 0), Pos(i, cut));
66+
}
67+
} else {
68+
for (var i = from.line; i < end; ++i) {
69+
if (blankLines || nonWS.test(self.getLine(i)))
70+
self.replaceRange(commentString + pad, Pos(i, 0));
71+
}
72+
}
73+
});
74+
});
75+
76+
CodeMirror.defineExtension("blockComment", function(from, to, options) {
77+
if (!options) options = noOptions;
78+
var self = this, mode = self.getModeAt(from);
79+
var startString = options.blockCommentStart || mode.blockCommentStart;
80+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
81+
if (!startString || !endString) {
82+
if ((options.lineComment || mode.lineComment) && options.fullLines != false)
83+
self.lineComment(from, to, options);
84+
return;
85+
}
86+
87+
var end = Math.min(to.line, self.lastLine());
88+
if (end != from.line && to.ch == 0 && nonWS.test(self.getLine(end))) --end;
89+
90+
var pad = options.padding == null ? " " : options.padding;
91+
if (from.line > end) return;
92+
93+
self.operation(function() {
94+
if (options.fullLines != false) {
95+
var lastLineHasText = nonWS.test(self.getLine(end));
96+
self.replaceRange(pad + endString, Pos(end));
97+
self.replaceRange(startString + pad, Pos(from.line, 0));
98+
var lead = options.blockCommentLead || mode.blockCommentLead;
99+
if (lead != null) for (var i = from.line + 1; i <= end; ++i)
100+
if (i != end || lastLineHasText)
101+
self.replaceRange(lead + pad, Pos(i, 0));
102+
} else {
103+
self.replaceRange(endString, to);
104+
self.replaceRange(startString, from);
105+
}
106+
});
107+
});
108+
109+
CodeMirror.defineExtension("uncomment", function(from, to, options) {
110+
if (!options) options = noOptions;
111+
var self = this, mode = self.getModeAt(from);
112+
var end = Math.min(to.ch != 0 || to.line == from.line ? to.line : to.line - 1, self.lastLine()), start = Math.min(from.line, end);
113+
114+
// Try finding line comments
115+
var lineString = options.lineComment || mode.lineComment, lines = [];
116+
var pad = options.padding == null ? " " : options.padding, didSomething;
117+
lineComment: {
118+
if (!lineString) break lineComment;
119+
for (var i = start; i <= end; ++i) {
120+
var line = self.getLine(i);
121+
var found = line.indexOf(lineString);
122+
if (found > -1 && !/comment/.test(self.getTokenTypeAt(Pos(i, found + 1)))) found = -1;
123+
if (found == -1 && (i != end || i == start) && nonWS.test(line)) break lineComment;
124+
if (found > -1 && nonWS.test(line.slice(0, found))) break lineComment;
125+
lines.push(line);
126+
}
127+
self.operation(function() {
128+
for (var i = start; i <= end; ++i) {
129+
var line = lines[i - start];
130+
var pos = line.indexOf(lineString), endPos = pos + lineString.length;
131+
if (pos < 0) continue;
132+
if (line.slice(endPos, endPos + pad.length) == pad) endPos += pad.length;
133+
didSomething = true;
134+
self.replaceRange("", Pos(i, pos), Pos(i, endPos));
135+
}
136+
});
137+
if (didSomething) return true;
138+
}
139+
140+
// Try block comments
141+
var startString = options.blockCommentStart || mode.blockCommentStart;
142+
var endString = options.blockCommentEnd || mode.blockCommentEnd;
143+
if (!startString || !endString) return false;
144+
var lead = options.blockCommentLead || mode.blockCommentLead;
145+
var startLine = self.getLine(start), endLine = end == start ? startLine : self.getLine(end);
146+
var open = startLine.indexOf(startString), close = endLine.lastIndexOf(endString);
147+
if (close == -1 && start != end) {
148+
endLine = self.getLine(--end);
149+
close = endLine.lastIndexOf(endString);
150+
}
151+
if (open == -1 || close == -1 ||
152+
!/comment/.test(self.getTokenTypeAt(Pos(start, open + 1))) ||
153+
!/comment/.test(self.getTokenTypeAt(Pos(end, close + 1))))
154+
return false;
155+
156+
// Avoid killing block comments completely outside the selection.
157+
// Positions of the last startString before the start of the selection, and the first endString after it.
158+
var lastStart = startLine.lastIndexOf(startString, from.ch);
159+
var firstEnd = lastStart == -1 ? -1 : startLine.slice(0, from.ch).indexOf(endString, lastStart + startString.length);
160+
if (lastStart != -1 && firstEnd != -1 && firstEnd + endString.length != from.ch) return false;
161+
// Positions of the first endString after the end of the selection, and the last startString before it.
162+
firstEnd = endLine.indexOf(endString, to.ch);
163+
var almostLastStart = endLine.slice(to.ch).lastIndexOf(startString, firstEnd - to.ch);
164+
lastStart = (firstEnd == -1 || almostLastStart == -1) ? -1 : to.ch + almostLastStart;
165+
if (firstEnd != -1 && lastStart != -1 && lastStart != to.ch) return false;
166+
167+
self.operation(function() {
168+
self.replaceRange("", Pos(end, close - (pad && endLine.slice(close - pad.length, close) == pad ? pad.length : 0)),
169+
Pos(end, close + endString.length));
170+
var openEnd = open + startString.length;
171+
if (pad && startLine.slice(openEnd, openEnd + pad.length) == pad) openEnd += pad.length;
172+
self.replaceRange("", Pos(start, open), Pos(start, openEnd));
173+
if (lead) for (var i = start + 1; i <= end; ++i) {
174+
var line = self.getLine(i), found = line.indexOf(lead);
175+
if (found == -1 || nonWS.test(line.slice(0, found))) continue;
176+
var foundEnd = found + lead.length;
177+
if (pad && line.slice(foundEnd, foundEnd + pad.length) == pad) foundEnd += pad.length;
178+
self.replaceRange("", Pos(i, found), Pos(i, foundEnd));
179+
}
180+
});
181+
return true;
182+
});
183+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
var modes = ["clike", "css", "javascript"];
13+
14+
for (var i = 0; i < modes.length; ++i)
15+
CodeMirror.extendMode(modes[i], {blockCommentContinue: " * "});
16+
17+
function continueComment(cm) {
18+
if (cm.getOption("disableInput")) return CodeMirror.Pass;
19+
var ranges = cm.listSelections(), mode, inserts = [];
20+
for (var i = 0; i < ranges.length; i++) {
21+
var pos = ranges[i].head, token = cm.getTokenAt(pos);
22+
if (token.type != "comment") return CodeMirror.Pass;
23+
var modeHere = CodeMirror.innerMode(cm.getMode(), token.state).mode;
24+
if (!mode) mode = modeHere;
25+
else if (mode != modeHere) return CodeMirror.Pass;
26+
27+
var insert = null;
28+
if (mode.blockCommentStart && mode.blockCommentContinue) {
29+
var end = token.string.indexOf(mode.blockCommentEnd);
30+
var full = cm.getRange(CodeMirror.Pos(pos.line, 0), CodeMirror.Pos(pos.line, token.end)), found;
31+
if (end != -1 && end == token.string.length - mode.blockCommentEnd.length && pos.ch >= end) {
32+
// Comment ended, don't continue it
33+
} else if (token.string.indexOf(mode.blockCommentStart) == 0) {
34+
insert = full.slice(0, token.start);
35+
if (!/^\s*$/.test(insert)) {
36+
insert = "";
37+
for (var j = 0; j < token.start; ++j) insert += " ";
38+
}
39+
} else if ((found = full.indexOf(mode.blockCommentContinue)) != -1 &&
40+
found + mode.blockCommentContinue.length > token.start &&
41+
/^\s*$/.test(full.slice(0, found))) {
42+
insert = full.slice(0, found);
43+
}
44+
if (insert != null) insert += mode.blockCommentContinue;
45+
}
46+
if (insert == null && mode.lineComment && continueLineCommentEnabled(cm)) {
47+
var line = cm.getLine(pos.line), found = line.indexOf(mode.lineComment);
48+
if (found > -1) {
49+
insert = line.slice(0, found);
50+
if (/\S/.test(insert)) insert = null;
51+
else insert += mode.lineComment + line.slice(found + mode.lineComment.length).match(/^\s*/)[0];
52+
}
53+
}
54+
if (insert == null) return CodeMirror.Pass;
55+
inserts[i] = "\n" + insert;
56+
}
57+
58+
cm.operation(function() {
59+
for (var i = ranges.length - 1; i >= 0; i--)
60+
cm.replaceRange(inserts[i], ranges[i].from(), ranges[i].to(), "+insert");
61+
});
62+
}
63+
64+
function continueLineCommentEnabled(cm) {
65+
var opt = cm.getOption("continueComments");
66+
if (opt && typeof opt == "object")
67+
return opt.continueLineComment !== false;
68+
return true;
69+
}
70+
71+
CodeMirror.defineOption("continueComments", null, function(cm, val, prev) {
72+
if (prev && prev != CodeMirror.Init)
73+
cm.removeKeyMap("continueComment");
74+
if (val) {
75+
var key = "Enter";
76+
if (typeof val == "string")
77+
key = val;
78+
else if (typeof val == "object" && val.key)
79+
key = val.key;
80+
var map = {name: "continueComment"};
81+
map[key] = continueComment;
82+
cm.addKeyMap(map);
83+
}
84+
});
85+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.CodeMirror-dialog {
2+
position: absolute;
3+
left: 0; right: 0;
4+
background: white;
5+
z-index: 15;
6+
padding: .1em .8em;
7+
overflow: hidden;
8+
color: #333;
9+
}
10+
11+
.CodeMirror-dialog-top {
12+
border-bottom: 1px solid #eee;
13+
top: 0;
14+
}
15+
16+
.CodeMirror-dialog-bottom {
17+
border-top: 1px solid #eee;
18+
bottom: 0;
19+
}
20+
21+
.CodeMirror-dialog input {
22+
border: none;
23+
outline: none;
24+
background: transparent;
25+
width: 20em;
26+
color: inherit;
27+
font-family: monospace;
28+
}
29+
30+
.CodeMirror-dialog button {
31+
font-size: 70%;
32+
}

0 commit comments

Comments
 (0)