cm_hl.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // custom mode
  2. 'use strict';
  3. import CodeMirror from 'codemirror';
  4. export default function () {
  5. CodeMirror.defineMode('host', function () {
  6. function tokenBase(stream) {
  7. if (stream.eatSpace()) return null;
  8. var sol = stream.sol();
  9. var ch = stream.next();
  10. var s = stream.string;
  11. if (ch === '#') {
  12. stream.skipToEnd();
  13. return 'comment';
  14. }
  15. if (!s.match(/^\s*([\d\.]+|[\da-f:\.%lo]+)\s+\w/i)) {
  16. return 'error';
  17. }
  18. if (sol && ch.match(/[\w\.:%]/)) {
  19. stream.eatWhile(/[\w\.:%]/);
  20. return 'ip';
  21. }
  22. return null;
  23. }
  24. function tokenize(stream, state) {
  25. return (state.tokens[0] || tokenBase)(stream, state);
  26. }
  27. return {
  28. startState: function () {
  29. return {tokens: []};
  30. },
  31. token: function (stream, state) {
  32. return tokenize(stream, state);
  33. },
  34. lineComment: '#'
  35. };
  36. });
  37. //CodeMirror.defineMIME('text/x-host', 'host');
  38. }