prism-flow.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. (function (Prism) {
  2. Prism.languages.flow = Prism.languages.extend('javascript', {});
  3. Prism.languages.insertBefore('flow', 'keyword', {
  4. 'type': [
  5. {
  6. pattern: /\b(?:[Bb]oolean|Function|[Nn]umber|[Ss]tring|[Ss]ymbol|any|mixed|null|void)\b/,
  7. alias: 'class-name'
  8. }
  9. ]
  10. });
  11. Prism.languages.flow['function-variable'].pattern = /(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=\s*(?:function\b|(?:\([^()]*\)(?:\s*:\s*\w+)?|(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/i;
  12. delete Prism.languages.flow['parameter'];
  13. Prism.languages.insertBefore('flow', 'operator', {
  14. 'flow-punctuation': {
  15. pattern: /\{\||\|\}/,
  16. alias: 'punctuation'
  17. }
  18. });
  19. if (!Array.isArray(Prism.languages.flow.keyword)) {
  20. Prism.languages.flow.keyword = [Prism.languages.flow.keyword];
  21. }
  22. Prism.languages.flow.keyword.unshift(
  23. {
  24. pattern: /(^|[^$]\b)(?:Class|declare|opaque|type)\b(?!\$)/,
  25. lookbehind: true
  26. },
  27. {
  28. pattern: /(^|[^$]\B)\$(?:Diff|Enum|Exact|Keys|ObjMap|PropertyType|Record|Shape|Subtype|Supertype|await)\b(?!\$)/,
  29. lookbehind: true
  30. }
  31. );
  32. }(Prism));