json.js 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Language: JSON
  3. Author: Ivan Sagalaev <[email protected]>
  4. Category: common, protocols
  5. */
  6. function(hljs) {
  7. var LITERALS = {literal: 'true false null'};
  8. var TYPES = [
  9. hljs.QUOTE_STRING_MODE,
  10. hljs.C_NUMBER_MODE
  11. ];
  12. var VALUE_CONTAINER = {
  13. end: ',', endsWithParent: true, excludeEnd: true,
  14. contains: TYPES,
  15. keywords: LITERALS
  16. };
  17. var OBJECT = {
  18. begin: '{', end: '}',
  19. contains: [
  20. {
  21. className: 'attr',
  22. begin: /"/, end: /"/,
  23. contains: [hljs.BACKSLASH_ESCAPE],
  24. illegal: '\\n',
  25. },
  26. hljs.inherit(VALUE_CONTAINER, {begin: /:/})
  27. ],
  28. illegal: '\\S'
  29. };
  30. var ARRAY = {
  31. begin: '\\[', end: '\\]',
  32. contains: [hljs.inherit(VALUE_CONTAINER)], // inherit is a workaround for a bug that makes shared modes with endsWithParent compile only the ending of one of the parents
  33. illegal: '\\S'
  34. };
  35. TYPES.splice(TYPES.length, 0, OBJECT, ARRAY);
  36. return {
  37. contains: TYPES,
  38. keywords: LITERALS,
  39. illegal: '\\S'
  40. };
  41. }