prism-plant-uml.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. (function (Prism) {
  2. var variable = /\$\w+|%[a-z]+%/;
  3. var arrowAttr = /\[[^[\]]*\]/.source;
  4. var arrowDirection = /(?:[drlu]|do|down|le|left|ri|right|up)/.source;
  5. var arrowBody = '(?:-+' + arrowDirection + '-+|\\.+' + arrowDirection + '\\.+|-+(?:' + arrowAttr + '-*)?|' + arrowAttr + '-+|\\.+(?:' + arrowAttr + '\\.*)?|' + arrowAttr + '\\.+)';
  6. var arrowLeft = /(?:<{1,2}|\/{1,2}|\\{1,2}|<\||[#*^+}xo])/.source;
  7. var arrowRight = /(?:>{1,2}|\/{1,2}|\\{1,2}|\|>|[#*^+{xo])/.source;
  8. var arrowPrefix = /[[?]?[ox]?/.source;
  9. var arrowSuffix = /[ox]?[\]?]?/.source;
  10. var arrow =
  11. arrowPrefix +
  12. '(?:' +
  13. arrowBody + arrowRight +
  14. '|' +
  15. arrowLeft + arrowBody + '(?:' + arrowRight + ')?' +
  16. ')' +
  17. arrowSuffix;
  18. Prism.languages['plant-uml'] = {
  19. 'comment': {
  20. pattern: /(^[ \t]*)(?:'.*|\/'[\s\S]*?'\/)/m,
  21. lookbehind: true,
  22. greedy: true
  23. },
  24. 'preprocessor': {
  25. pattern: /(^[ \t]*)!.*/m,
  26. lookbehind: true,
  27. greedy: true,
  28. alias: 'property',
  29. inside: {
  30. 'variable': variable
  31. }
  32. },
  33. 'delimiter': {
  34. pattern: /(^[ \t]*)@(?:end|start)uml\b/m,
  35. lookbehind: true,
  36. greedy: true,
  37. alias: 'punctuation'
  38. },
  39. 'arrow': {
  40. pattern: RegExp(/(^|[^-.<>?|\\[\]ox])/.source + arrow + /(?![-.<>?|\\\]ox])/.source),
  41. lookbehind: true,
  42. greedy: true,
  43. alias: 'operator',
  44. inside: {
  45. 'expression': {
  46. pattern: /(\[)[^[\]]+(?=\])/,
  47. lookbehind: true,
  48. inside: null // see below
  49. },
  50. 'punctuation': /\[(?=$|\])|^\]/
  51. }
  52. },
  53. 'string': {
  54. pattern: /"[^"]*"/,
  55. greedy: true
  56. },
  57. 'text': {
  58. pattern: /(\[[ \t]*[\r\n]+(?![\r\n]))[^\]]*(?=\])/,
  59. lookbehind: true,
  60. greedy: true,
  61. alias: 'string'
  62. },
  63. 'keyword': [
  64. {
  65. pattern: /^([ \t]*)(?:abstract\s+class|end\s+(?:box|fork|group|merge|note|ref|split|title)|(?:fork|split)(?:\s+again)?|activate|actor|agent|alt|annotation|artifact|autoactivate|autonumber|backward|binary|boundary|box|break|caption|card|case|circle|class|clock|cloud|collections|component|concise|control|create|critical|database|deactivate|destroy|detach|diamond|else|elseif|end|end[hr]note|endif|endswitch|endwhile|entity|enum|file|folder|footer|frame|group|[hr]?note|header|hexagon|hide|if|interface|label|legend|loop|map|namespace|network|newpage|node|nwdiag|object|opt|package|page|par|participant|person|queue|rectangle|ref|remove|repeat|restore|return|robust|scale|set|show|skinparam|stack|start|state|stop|storage|switch|title|together|usecase|usecase\/|while)(?=\s|$)/m,
  66. lookbehind: true,
  67. greedy: true
  68. },
  69. /\b(?:elseif|equals|not|while)(?=\s*\()/,
  70. /\b(?:as|is|then)\b/
  71. ],
  72. 'divider': {
  73. pattern: /^==.+==$/m,
  74. greedy: true,
  75. alias: 'important'
  76. },
  77. 'time': {
  78. pattern: /@(?:\d+(?:[:/]\d+){2}|[+-]?\d+|:[a-z]\w*(?:[+-]\d+)?)\b/i,
  79. greedy: true,
  80. alias: 'number'
  81. },
  82. 'color': {
  83. pattern: /#(?:[a-z_]+|[a-fA-F0-9]+)\b/,
  84. alias: 'symbol'
  85. },
  86. 'variable': variable,
  87. 'punctuation': /[:,;()[\]{}]|\.{3}/
  88. };
  89. Prism.languages['plant-uml'].arrow.inside.expression.inside = Prism.languages['plant-uml'];
  90. Prism.languages['plantuml'] = Prism.languages['plant-uml'];
  91. }(Prism));