prism-jsdoc.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. (function (Prism) {
  2. var javascript = Prism.languages.javascript;
  3. var type = /\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})+\}/.source;
  4. var parameterPrefix = '(@(?:arg|argument|param|property)\\s+(?:' + type + '\\s+)?)';
  5. Prism.languages.jsdoc = Prism.languages.extend('javadoclike', {
  6. 'parameter': {
  7. // @param {string} foo - foo bar
  8. pattern: RegExp(parameterPrefix + /(?:(?!\s)[$\w\xA0-\uFFFF.])+(?=\s|$)/.source),
  9. lookbehind: true,
  10. inside: {
  11. 'punctuation': /\./
  12. }
  13. }
  14. });
  15. Prism.languages.insertBefore('jsdoc', 'keyword', {
  16. 'optional-parameter': {
  17. // @param {string} [baz.foo="bar"] foo bar
  18. pattern: RegExp(parameterPrefix + /\[(?:(?!\s)[$\w\xA0-\uFFFF.])+(?:=[^[\]]+)?\](?=\s|$)/.source),
  19. lookbehind: true,
  20. inside: {
  21. 'parameter': {
  22. pattern: /(^\[)[$\w\xA0-\uFFFF\.]+/,
  23. lookbehind: true,
  24. inside: {
  25. 'punctuation': /\./
  26. }
  27. },
  28. 'code': {
  29. pattern: /(=)[\s\S]*(?=\]$)/,
  30. lookbehind: true,
  31. inside: javascript,
  32. alias: 'language-javascript'
  33. },
  34. 'punctuation': /[=[\]]/
  35. }
  36. },
  37. 'class-name': [
  38. {
  39. pattern: RegExp(/(@(?:augments|class|extends|interface|memberof!?|template|this|typedef)\s+(?:<TYPE>\s+)?)[A-Z]\w*(?:\.[A-Z]\w*)*/.source.replace(/<TYPE>/g, function () { return type; })),
  40. lookbehind: true,
  41. inside: {
  42. 'punctuation': /\./
  43. }
  44. },
  45. {
  46. pattern: RegExp('(@[a-z]+\\s+)' + type),
  47. lookbehind: true,
  48. inside: {
  49. 'string': javascript.string,
  50. 'number': javascript.number,
  51. 'boolean': javascript.boolean,
  52. 'keyword': Prism.languages.typescript.keyword,
  53. 'operator': /=>|\.\.\.|[&|?:*]/,
  54. 'punctuation': /[.,;=<>{}()[\]]/
  55. }
  56. }
  57. ],
  58. 'example': {
  59. pattern: /(@example\s+(?!\s))(?:[^@\s]|\s+(?!\s))+?(?=\s*(?:\*\s*)?(?:@\w|\*\/))/,
  60. lookbehind: true,
  61. inside: {
  62. 'code': {
  63. pattern: /^([\t ]*(?:\*\s*)?)\S.*$/m,
  64. lookbehind: true,
  65. inside: javascript,
  66. alias: 'language-javascript'
  67. }
  68. }
  69. }
  70. });
  71. Prism.languages.javadoclike.addSupport('javascript', Prism.languages.jsdoc);
  72. }(Prism));