ini.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. module.exports = function(hljs) {
  2. var NUMBERS = {
  3. className: 'number',
  4. relevance: 0,
  5. variants: [
  6. { begin: /([\+\-]+)?[\d]+_[\d_]+/ },
  7. { begin: hljs.NUMBER_RE }
  8. ]
  9. };
  10. var COMMENTS = hljs.COMMENT();
  11. COMMENTS.variants = [
  12. {begin: /;/, end: /$/},
  13. {begin: /#/, end: /$/},
  14. ];
  15. var VARIABLES = {
  16. className: 'variable',
  17. variants: [
  18. { begin: /\$[\w\d"][\w\d_]*/ },
  19. { begin: /\$\{(.*?)}/ }
  20. ]
  21. };
  22. var LITERALS = {
  23. className: 'literal',
  24. begin: /\bon|off|true|false|yes|no\b/
  25. };
  26. var STRINGS = {
  27. className: "string",
  28. contains: [hljs.BACKSLASH_ESCAPE],
  29. variants: [
  30. { begin: "'''", end: "'''", relevance: 10 },
  31. { begin: '"""', end: '"""', relevance: 10 },
  32. { begin: '"', end: '"' },
  33. { begin: "'", end: "'" }
  34. ]
  35. };
  36. var ARRAY = {
  37. begin: /\[/, end: /\]/,
  38. contains: [
  39. COMMENTS,
  40. LITERALS,
  41. VARIABLES,
  42. STRINGS,
  43. NUMBERS,
  44. 'self'
  45. ],
  46. relevance:0
  47. };
  48. return {
  49. aliases: ['toml'],
  50. case_insensitive: true,
  51. illegal: /\S/,
  52. contains: [
  53. COMMENTS,
  54. {
  55. className: 'section',
  56. begin: /\[+/, end: /\]+/
  57. },
  58. {
  59. begin: /^[a-z0-9\[\]_\.-]+(?=\s*=\s*)/,
  60. className: 'attr',
  61. starts: {
  62. end: /$/,
  63. contains: [
  64. COMMENTS,
  65. ARRAY,
  66. LITERALS,
  67. VARIABLES,
  68. STRINGS,
  69. NUMBERS
  70. ]
  71. }
  72. }
  73. ]
  74. };
  75. };