all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/diff/diff.js (view raw)

 1// CodeMirror, copyright (c) by Marijn Haverbeke and others
 2// Distributed under an MIT license: https://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
14CodeMirror.defineMode("diff", function() {
15
16  var TOKEN_NAMES = {
17    '+': 'positive',
18    '-': 'negative',
19    '@': 'meta'
20  };
21
22  return {
23    token: function(stream) {
24      var tw_pos = stream.string.search(/[\t ]+?$/);
25
26      if (!stream.sol() || tw_pos === 0) {
27        stream.skipToEnd();
28        return ("error " + (
29          TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
30      }
31
32      var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd();
33
34      if (tw_pos === -1) {
35        stream.skipToEnd();
36      } else {
37        stream.pos = tw_pos;
38      }
39
40      return token_name;
41    }
42  };
43});
44
45CodeMirror.defineMIME("text/x-diff", "diff");
46
47});