json.js 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. module.exports = function(hljs) {
  2. var LITERALS = {literal: 'true false null'};
  3. var TYPES = [
  4. hljs.QUOTE_STRING_MODE,
  5. hljs.C_NUMBER_MODE
  6. ];
  7. var VALUE_CONTAINER = {
  8. end: ',', endsWithParent: true, excludeEnd: true,
  9. contains: TYPES,
  10. keywords: LITERALS
  11. };
  12. var OBJECT = {
  13. begin: '{', end: '}',
  14. contains: [
  15. {
  16. className: 'attr',
  17. begin: /"/, end: /"/,
  18. contains: [hljs.BACKSLASH_ESCAPE],
  19. illegal: '\\n',
  20. },
  21. hljs.inherit(VALUE_CONTAINER, {begin: /:/})
  22. ],
  23. illegal: '\\S'
  24. };
  25. var ARRAY = {
  26. begin: '\\[', end: '\\]',
  27. 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
  28. illegal: '\\S'
  29. };
  30. TYPES.splice(TYPES.length, 0, OBJECT, ARRAY);
  31. return {
  32. contains: TYPES,
  33. keywords: LITERALS,
  34. illegal: '\\S'
  35. };
  36. };