prism-mermaid.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. Prism.languages.mermaid = {
  2. 'comment': {
  3. pattern: /%%.*/,
  4. greedy: true
  5. },
  6. 'style': {
  7. pattern: /^([ \t]*(?:classDef|linkStyle|style)[ \t]+[\w$-]+[ \t]+)\w.*[^\s;]/m,
  8. lookbehind: true,
  9. inside: {
  10. 'property': /\b\w[\w-]*(?=[ \t]*:)/,
  11. 'operator': /:/,
  12. 'punctuation': /,/
  13. }
  14. },
  15. 'inter-arrow-label': {
  16. pattern: /([^<>ox.=-])(?:-[-.]|==)(?![<>ox.=-])[ \t]*(?:"[^"\r\n]*"|[^\s".=-](?:[^\r\n.=-]*[^\s.=-])?)[ \t]*(?:\.+->?|--+[->]|==+[=>])(?![<>ox.=-])/,
  17. lookbehind: true,
  18. greedy: true,
  19. inside: {
  20. 'arrow': {
  21. pattern: /(?:\.+->?|--+[->]|==+[=>])$/,
  22. alias: 'operator'
  23. },
  24. 'label': {
  25. pattern: /^([\s\S]{2}[ \t]*)\S(?:[\s\S]*\S)?/,
  26. lookbehind: true,
  27. alias: 'property'
  28. },
  29. 'arrow-head': {
  30. pattern: /^\S+/,
  31. alias: ['arrow', 'operator']
  32. }
  33. }
  34. },
  35. 'arrow': [
  36. // This might look complex but it really isn't.
  37. // There are many possible arrows (see tests) and it's impossible to fit all of them into one pattern. The
  38. // problem is that we only have one lookbehind per pattern. However, we cannot disallow too many arrow
  39. // characters in the one lookbehind because that would create too many false negatives. So we have to split the
  40. // arrows into different patterns.
  41. {
  42. // ER diagram
  43. pattern: /(^|[^{}|o.-])[|}][|o](?:--|\.\.)[|o][|{](?![{}|o.-])/,
  44. lookbehind: true,
  45. alias: 'operator'
  46. },
  47. {
  48. // flow chart
  49. // (?:==+|--+|-\.*-)
  50. pattern: /(^|[^<>ox.=-])(?:[<ox](?:==+|--+|-\.*-)[>ox]?|(?:==+|--+|-\.*-)[>ox]|===+|---+|-\.+-)(?![<>ox.=-])/,
  51. lookbehind: true,
  52. alias: 'operator'
  53. },
  54. {
  55. // sequence diagram
  56. pattern: /(^|[^<>()x-])(?:--?(?:>>|[x>)])(?![<>()x])|(?:<<|[x<(])--?(?!-))/,
  57. lookbehind: true,
  58. alias: 'operator'
  59. },
  60. {
  61. // class diagram
  62. pattern: /(^|[^<>|*o.-])(?:[*o]--|--[*o]|<\|?(?:--|\.\.)|(?:--|\.\.)\|?>|--|\.\.)(?![<>|*o.-])/,
  63. lookbehind: true,
  64. alias: 'operator'
  65. },
  66. ],
  67. 'label': {
  68. pattern: /(^|[^|<])\|(?:[^\r\n"|]|"[^"\r\n]*")+\|/,
  69. lookbehind: true,
  70. greedy: true,
  71. alias: 'property'
  72. },
  73. 'text': {
  74. pattern: /(?:[(\[{]+|\b>)(?:[^\r\n"()\[\]{}]|"[^"\r\n]*")+(?:[)\]}]+|>)/,
  75. alias: 'string'
  76. },
  77. 'string': {
  78. pattern: /"[^"\r\n]*"/,
  79. greedy: true
  80. },
  81. 'annotation': {
  82. pattern: /<<(?:abstract|choice|enumeration|fork|interface|join|service)>>|\[\[(?:choice|fork|join)\]\]/i,
  83. alias: 'important'
  84. },
  85. 'keyword': [
  86. // This language has both case-sensitive and case-insensitive keywords
  87. {
  88. pattern: /(^[ \t]*)(?:action|callback|class|classDef|classDiagram|click|direction|erDiagram|flowchart|gantt|gitGraph|graph|journey|link|linkStyle|pie|requirementDiagram|sequenceDiagram|stateDiagram|stateDiagram-v2|style|subgraph)(?![\w$-])/m,
  89. lookbehind: true,
  90. greedy: true
  91. },
  92. {
  93. pattern: /(^[ \t]*)(?:activate|alt|and|as|autonumber|deactivate|else|end(?:[ \t]+note)?|loop|opt|par|participant|rect|state|note[ \t]+(?:over|(?:left|right)[ \t]+of))(?![\w$-])/im,
  94. lookbehind: true,
  95. greedy: true
  96. }
  97. ],
  98. 'entity': /#[a-z0-9]+;/,
  99. 'operator': {
  100. pattern: /(\w[ \t]*)&(?=[ \t]*\w)|:::|:/,
  101. lookbehind: true
  102. },
  103. 'punctuation': /[(){};]/
  104. };