prism-toml.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. (function (Prism) {
  2. var key = /(?:[\w-]+|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*")/.source;
  3. /**
  4. * @param {string} pattern
  5. */
  6. function insertKey(pattern) {
  7. return pattern.replace(/__/g, function () { return key; });
  8. }
  9. Prism.languages.toml = {
  10. 'comment': {
  11. pattern: /#.*/,
  12. greedy: true
  13. },
  14. 'table': {
  15. pattern: RegExp(insertKey(/(^[\t ]*\[\s*(?:\[\s*)?)__(?:\s*\.\s*__)*(?=\s*\])/.source), 'm'),
  16. lookbehind: true,
  17. greedy: true,
  18. alias: 'class-name'
  19. },
  20. 'key': {
  21. pattern: RegExp(insertKey(/(^[\t ]*|[{,]\s*)__(?:\s*\.\s*__)*(?=\s*=)/.source), 'm'),
  22. lookbehind: true,
  23. greedy: true,
  24. alias: 'property'
  25. },
  26. 'string': {
  27. pattern: /"""(?:\\[\s\S]|[^\\])*?"""|'''[\s\S]*?'''|'[^'\n\r]*'|"(?:\\.|[^\\"\r\n])*"/,
  28. greedy: true
  29. },
  30. 'date': [
  31. {
  32. // Offset Date-Time, Local Date-Time, Local Date
  33. pattern: /\b\d{4}-\d{2}-\d{2}(?:[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)?\b/i,
  34. alias: 'number'
  35. },
  36. {
  37. // Local Time
  38. pattern: /\b\d{2}:\d{2}:\d{2}(?:\.\d+)?\b/,
  39. alias: 'number'
  40. }
  41. ],
  42. 'number': /(?:\b0(?:x[\da-zA-Z]+(?:_[\da-zA-Z]+)*|o[0-7]+(?:_[0-7]+)*|b[10]+(?:_[10]+)*))\b|[-+]?\b\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?\b|[-+]?\b(?:inf|nan)\b/,
  43. 'boolean': /\b(?:false|true)\b/,
  44. 'punctuation': /[.,=[\]{}]/
  45. };
  46. }(Prism));