diff.js 1010 B

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