diff.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/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. });