nestedtext.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Language: NestedText
  3. Description: NestedText is a file format for holding data that is to be entered, edited, or viewed by people.
  4. Website: https://nestedtext.org/
  5. Category: config
  6. */
  7. /** @type LanguageFn */
  8. function nestedtext(hljs) {
  9. const NESTED = {
  10. match: [
  11. /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
  12. /[^:]+/,
  13. /:\s*/,
  14. /$/
  15. ],
  16. className: {
  17. 2: "attribute",
  18. 3: "punctuation"
  19. }
  20. };
  21. const DICTIONARY_ITEM = {
  22. match: [
  23. /^\s*(?=\S)/, // have to look forward here to avoid polynomial backtracking
  24. /[^:]*[^: ]/,
  25. /[ ]*:/,
  26. /[ ]/,
  27. /.*$/
  28. ],
  29. className: {
  30. 2: "attribute",
  31. 3: "punctuation",
  32. 5: "string"
  33. }
  34. };
  35. const STRING = {
  36. match: [
  37. /^\s*/,
  38. />/,
  39. /[ ]/,
  40. /.*$/
  41. ],
  42. className: {
  43. 2: "punctuation",
  44. 4: "string"
  45. }
  46. };
  47. const LIST_ITEM = {
  48. variants: [
  49. { match: [
  50. /^\s*/,
  51. /-/,
  52. /[ ]/,
  53. /.*$/
  54. ] },
  55. { match: [
  56. /^\s*/,
  57. /-$/
  58. ] }
  59. ],
  60. className: {
  61. 2: "bullet",
  62. 4: "string"
  63. }
  64. };
  65. return {
  66. name: 'Nested Text',
  67. aliases: [ 'nt' ],
  68. contains: [
  69. hljs.inherit(hljs.HASH_COMMENT_MODE, {
  70. begin: /^\s*(?=#)/,
  71. excludeBegin: true
  72. }),
  73. LIST_ITEM,
  74. STRING,
  75. NESTED,
  76. DICTIONARY_ITEM
  77. ]
  78. };
  79. }
  80. export { nestedtext as default };