prism-javadoc.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function (Prism) {
  2. var codeLinePattern = /(^(?:[\t ]*(?:\*\s*)*))[^*\s].*$/m;
  3. var memberReference = /#\s*\w+(?:\s*\([^()]*\))?/.source;
  4. var reference = /(?:\b[a-zA-Z]\w+\s*\.\s*)*\b[A-Z]\w*(?:\s*<mem>)?|<mem>/.source.replace(/<mem>/g, function () { return memberReference; });
  5. Prism.languages.javadoc = Prism.languages.extend('javadoclike', {});
  6. Prism.languages.insertBefore('javadoc', 'keyword', {
  7. 'reference': {
  8. pattern: RegExp(/(@(?:exception|link|linkplain|see|throws|value)\s+(?:\*\s*)?)/.source + '(?:' + reference + ')'),
  9. lookbehind: true,
  10. inside: {
  11. 'function': {
  12. pattern: /(#\s*)\w+(?=\s*\()/,
  13. lookbehind: true
  14. },
  15. 'field': {
  16. pattern: /(#\s*)\w+/,
  17. lookbehind: true
  18. },
  19. 'namespace': {
  20. pattern: /\b(?:[a-z]\w*\s*\.\s*)+/,
  21. inside: {
  22. 'punctuation': /\./
  23. }
  24. },
  25. 'class-name': /\b[A-Z]\w*/,
  26. 'keyword': Prism.languages.java.keyword,
  27. 'punctuation': /[#()[\],.]/
  28. }
  29. },
  30. 'class-name': {
  31. // @param <T> the first generic type parameter
  32. pattern: /(@param\s+)<[A-Z]\w*>/,
  33. lookbehind: true,
  34. inside: {
  35. 'punctuation': /[.<>]/
  36. }
  37. },
  38. 'code-section': [
  39. {
  40. pattern: /(\{@code\s+(?!\s))(?:[^\s{}]|\s+(?![\s}])|\{(?:[^{}]|\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*\})+(?=\s*\})/,
  41. lookbehind: true,
  42. inside: {
  43. 'code': {
  44. // there can't be any HTML inside of {@code} tags
  45. pattern: codeLinePattern,
  46. lookbehind: true,
  47. inside: Prism.languages.java,
  48. alias: 'language-java'
  49. }
  50. }
  51. },
  52. {
  53. pattern: /(<(code|pre|tt)>(?!<code>)\s*)\S(?:\S|\s+\S)*?(?=\s*<\/\2>)/,
  54. lookbehind: true,
  55. inside: {
  56. 'line': {
  57. pattern: codeLinePattern,
  58. lookbehind: true,
  59. inside: {
  60. // highlight HTML tags and entities
  61. 'tag': Prism.languages.markup.tag,
  62. 'entity': Prism.languages.markup.entity,
  63. 'code': {
  64. // everything else is Java code
  65. pattern: /.+/,
  66. inside: Prism.languages.java,
  67. alias: 'language-java'
  68. }
  69. }
  70. }
  71. }
  72. }
  73. ],
  74. 'tag': Prism.languages.markup.tag,
  75. 'entity': Prism.languages.markup.entity,
  76. });
  77. Prism.languages.javadoclike.addSupport('java', Prism.languages.javadoc);
  78. }(Prism));