mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
0be3c91823
Former-commit-id: 46c13d0c36c98e1c4cd7a0548c561dc70c0952ea [formerly 4a56a0bbffd2bb5b437c2c4e7497da0cd42dc306] [formerly c6e51179179dad88c1014b07d13e83f759ad6b6c [formerly 21cd7d092c
]]
Former-commit-id: e17744bea8af56671b35709b358bea7d4c9aaff5 [formerly 40b9fe4727f897ee471af9ffce8cd7780f22a612]
Former-commit-id: 0d2322553b3a177f74d4110044e1f801391daaeb
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
|
|
|
(function(mod) {
|
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
mod(require("../../lib/codemirror"));
|
|
else if (typeof define == "function" && define.amd) // AMD
|
|
define(["../../lib/codemirror"], mod);
|
|
else // Plain browser env
|
|
mod(CodeMirror);
|
|
})(function(CodeMirror) {
|
|
"use strict";
|
|
|
|
function errorIfNotEmpty(stream) {
|
|
var nonWS = stream.match(/^\s*\S/);
|
|
stream.skipToEnd();
|
|
return nonWS ? "error" : null;
|
|
}
|
|
|
|
CodeMirror.defineMode("asciiarmor", function() {
|
|
return {
|
|
token: function(stream, state) {
|
|
var m;
|
|
if (state.state == "top") {
|
|
if (stream.sol() && (m = stream.match(/^-----BEGIN (.*)?-----\s*$/))) {
|
|
state.state = "headers";
|
|
state.type = m[1];
|
|
return "tag";
|
|
}
|
|
return errorIfNotEmpty(stream);
|
|
} else if (state.state == "headers") {
|
|
if (stream.sol() && stream.match(/^\w+:/)) {
|
|
state.state = "header";
|
|
return "atom";
|
|
} else {
|
|
var result = errorIfNotEmpty(stream);
|
|
if (result) state.state = "body";
|
|
return result;
|
|
}
|
|
} else if (state.state == "header") {
|
|
stream.skipToEnd();
|
|
state.state = "headers";
|
|
return "string";
|
|
} else if (state.state == "body") {
|
|
if (stream.sol() && (m = stream.match(/^-----END (.*)?-----\s*$/))) {
|
|
if (m[1] != state.type) return "error";
|
|
state.state = "end";
|
|
return "tag";
|
|
} else {
|
|
if (stream.eatWhile(/[A-Za-z0-9+\/=]/)) {
|
|
return null;
|
|
} else {
|
|
stream.next();
|
|
return "error";
|
|
}
|
|
}
|
|
} else if (state.state == "end") {
|
|
return errorIfNotEmpty(stream);
|
|
}
|
|
},
|
|
blankLine: function(state) {
|
|
if (state.state == "headers") state.state = "body";
|
|
},
|
|
startState: function() {
|
|
return {state: "top", type: null};
|
|
}
|
|
};
|
|
});
|
|
|
|
CodeMirror.defineMIME("application/pgp", "asciiarmor");
|
|
CodeMirror.defineMIME("application/pgp-keys", "asciiarmor");
|
|
CodeMirror.defineMIME("application/pgp-signature", "asciiarmor");
|
|
});
|