GPQAPP
74 строки · 2.4 Кб
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
14function errorIfNotEmpty(stream) {15var nonWS = stream.match(/^\s*\S/);16stream.skipToEnd();17return nonWS ? "error" : null;18}19
20CodeMirror.defineMode("asciiarmor", function() {21return {22token: function(stream, state) {23var m;24if (state.state == "top") {25if (stream.sol() && (m = stream.match(/^-----BEGIN (.*)?-----\s*$/))) {26state.state = "headers";27state.type = m[1];28return "tag";29}30return errorIfNotEmpty(stream);31} else if (state.state == "headers") {32if (stream.sol() && stream.match(/^\w+:/)) {33state.state = "header";34return "atom";35} else {36var result = errorIfNotEmpty(stream);37if (result) state.state = "body";38return result;39}40} else if (state.state == "header") {41stream.skipToEnd();42state.state = "headers";43return "string";44} else if (state.state == "body") {45if (stream.sol() && (m = stream.match(/^-----END (.*)?-----\s*$/))) {46if (m[1] != state.type) return "error";47state.state = "end";48return "tag";49} else {50if (stream.eatWhile(/[A-Za-z0-9+\/=]/)) {51return null;52} else {53stream.next();54return "error";55}56}57} else if (state.state == "end") {58return errorIfNotEmpty(stream);59}60},61blankLine: function(state) {62if (state.state == "headers") state.state = "body";63},64startState: function() {65return {state: "top", type: null};66}67};68});69
70CodeMirror.defineMIME("application/pgp", "asciiarmor");71CodeMirror.defineMIME("application/pgp-encrypted", "asciiarmor");72CodeMirror.defineMIME("application/pgp-keys", "asciiarmor");73CodeMirror.defineMIME("application/pgp-signature", "asciiarmor");74});75