You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineMode("diff", function() {
  13. var TOKEN_NAMES = {
  14. '+': 'positive',
  15. '-': 'negative',
  16. '@': 'meta'
  17. };
  18. return {
  19. token: function(stream) {
  20. var tw_pos = stream.string.search(/[\t ]+?$/);
  21. if (!stream.sol() || tw_pos === 0) {
  22. stream.skipToEnd();
  23. return ("error " + (
  24. TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, '');
  25. }
  26. var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd();
  27. if (tw_pos === -1) {
  28. stream.skipToEnd();
  29. } else {
  30. stream.pos = tw_pos;
  31. }
  32. return token_name;
  33. }
  34. };
  35. });
  36. CodeMirror.defineMIME("text/x-diff", "diff");
  37. });