diff.js 1.3 KB

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