prism-yaml.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. Prism.languages.yaml = {
  2. 'scalar': {
  3. pattern: /([\-:]\s*(![^\s]+)?[ \t]*[|>])[ \t]*(?:(\n[ \t]+)[^\r\n]+(?:\3[^\r\n]+)*)/,
  4. lookbehind: true,
  5. alias: 'string'
  6. },
  7. 'comment': /#[^\n]+/,
  8. 'key': {
  9. pattern: /(\s*[:\-,[{\n?][ \t]*(![^\s]+)?[ \t]*)[^\n{[\]},#]+?(?=\s*:\s)/,
  10. lookbehind: true,
  11. alias: 'atrule'
  12. },
  13. 'directive': {
  14. pattern: /((^|\n)[ \t]*)%[^\n]+/,
  15. lookbehind: true,
  16. alias: 'important'
  17. },
  18. 'datetime': {
  19. pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(\d{4}-\d\d?-\d\d?([tT]|[ \t]+)\d\d?:\d{2}:\d{2}(\.\d*)?[ \t]*(Z|[-+]\d\d?(:\d{2})?)?|\d{4}-\d{2}-\d{2}|\d\d?:\d{2}(:\d{2}(\.\d*)?)?)(?=[ \t]*(\n|$|,|]|}))/,
  20. lookbehind: true,
  21. alias: 'number'
  22. },
  23. 'boolean': {
  24. pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(true|false)[ \t]*(?=\n|$|,|]|})/i,
  25. lookbehind: true,
  26. alias: 'important'
  27. },
  28. 'null': {
  29. pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)(null|~)[ \t]*(?=\n|$|,|]|})/i,
  30. lookbehind: true,
  31. alias: 'important'
  32. },
  33. 'string': {
  34. pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')(?=[ \t]*(\n|$|,|]|}))/,
  35. lookbehind: true
  36. },
  37. 'number': {
  38. pattern: /([:\-,[{]\s*(![^\s]+)?[ \t]*)[+\-]?(0x[\dA-Fa-f]+|0o[0-7]+|(\d+\.?\d*|\.?\d+)(e[\+\-]?\d+)?|\.inf|\.nan)[ \t]*(?=\n|$|,|]|})/i,
  39. lookbehind: true
  40. },
  41. 'tag': /![^\s]+/,
  42. 'important': /[&*][\w]+/,
  43. 'punctuation': /([:[\]{}\-,|>?]|---|\.\.\.)/
  44. };