prism-dot.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // https://www.graphviz.org/doc/info/lang.html
  2. (function (Prism) {
  3. var ID = '(?:' + [
  4. // an identifier
  5. /[a-zA-Z_\x80-\uFFFF][\w\x80-\uFFFF]*/.source,
  6. // a number
  7. /-?(?:\.\d+|\d+(?:\.\d*)?)/.source,
  8. // a double-quoted string
  9. /"[^"\\]*(?:\\[\s\S][^"\\]*)*"/.source,
  10. // HTML-like string
  11. /<(?:[^<>]|(?!<!--)<(?:[^<>"']|"[^"]*"|'[^']*')+>|<!--(?:[^-]|-(?!->))*-->)*>/.source
  12. ].join('|') + ')';
  13. var IDInside = {
  14. 'markup': {
  15. pattern: /(^<)[\s\S]+(?=>$)/,
  16. lookbehind: true,
  17. alias: ['language-markup', 'language-html', 'language-xml'],
  18. inside: Prism.languages.markup
  19. }
  20. };
  21. /**
  22. * @param {string} source
  23. * @param {string} flags
  24. * @returns {RegExp}
  25. */
  26. function withID(source, flags) {
  27. return RegExp(source.replace(/<ID>/g, function () { return ID; }), flags);
  28. }
  29. Prism.languages.dot = {
  30. 'comment': {
  31. pattern: /\/\/.*|\/\*[\s\S]*?\*\/|^#.*/m,
  32. greedy: true
  33. },
  34. 'graph-name': {
  35. pattern: withID(/(\b(?:digraph|graph|subgraph)[ \t\r\n]+)<ID>/.source, 'i'),
  36. lookbehind: true,
  37. greedy: true,
  38. alias: 'class-name',
  39. inside: IDInside
  40. },
  41. 'attr-value': {
  42. pattern: withID(/(=[ \t\r\n]*)<ID>/.source),
  43. lookbehind: true,
  44. greedy: true,
  45. inside: IDInside
  46. },
  47. 'attr-name': {
  48. pattern: withID(/([\[;, \t\r\n])<ID>(?=[ \t\r\n]*=)/.source),
  49. lookbehind: true,
  50. greedy: true,
  51. inside: IDInside
  52. },
  53. 'keyword': /\b(?:digraph|edge|graph|node|strict|subgraph)\b/i,
  54. 'compass-point': {
  55. pattern: /(:[ \t\r\n]*)(?:[ewc_]|[ns][ew]?)(?![\w\x80-\uFFFF])/,
  56. lookbehind: true,
  57. alias: 'builtin'
  58. },
  59. 'node': {
  60. pattern: withID(/(^|[^-.\w\x80-\uFFFF\\])<ID>/.source),
  61. lookbehind: true,
  62. greedy: true,
  63. inside: IDInside
  64. },
  65. 'operator': /[=:]|-[->]/,
  66. 'punctuation': /[\[\]{};,]/
  67. };
  68. Prism.languages.gv = Prism.languages.dot;
  69. }(Prism));