MediaWiki:Gadget-prism-language-java.js

来自萌娘共享
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
  1. /**
  2. * -------------------------------------------------------------------------
  3. * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
  4. * -------------------------------------------------------------------------
  5. */
  6. var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism-language-java/Gadget-prism-language-java.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}';
  7. /* <pre> */
  8. "use strict";
  9. (function (Prism) {
  10. var keywords = /\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/;
  11. var classNamePrefix = /(?:[a-z]\w*\s*\.\s*)*(?:[A-Z]\w*\s*\.\s*)*/.source;
  12. var className = {
  13. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z](?:[\d_A-Z]*[a-z]\w*)?\b/.source),
  14. lookbehind: true,
  15. inside: {
  16. 'namespace': {
  17. pattern: /^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,
  18. inside: {
  19. 'punctuation': /\./
  20. }
  21. },
  22. 'punctuation': /\./
  23. }
  24. };
  25. Prism.languages.java = Prism.languages.extend('clike', {
  26. 'string': {
  27. pattern: /(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,
  28. lookbehind: true,
  29. greedy: true
  30. },
  31. 'class-name': [
  32. className,
  33. {
  34. pattern: RegExp(/(^|[^\w.])/.source + classNamePrefix + /[A-Z]\w*(?=\s+\w+\s*[;,=()]|\s*(?:\[[\s,]*\]\s*)?::\s*new\b)/.source),
  35. lookbehind: true,
  36. inside: className.inside
  37. },
  38. {
  39. pattern: RegExp(/(\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\s+)/.source + classNamePrefix + /[A-Z]\w*\b/.source),
  40. lookbehind: true,
  41. inside: className.inside
  42. }
  43. ],
  44. 'keyword': keywords,
  45. 'function': [
  46. Prism.languages.clike["function"],
  47. {
  48. pattern: /(::\s*)[a-z_]\w*/,
  49. lookbehind: true
  50. }
  51. ],
  52. 'number': /\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,
  53. 'operator': {
  54. pattern: /(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,
  55. lookbehind: true
  56. },
  57. 'constant': /\b[A-Z][A-Z_\d]+\b/
  58. });
  59. Prism.languages.insertBefore('java', 'string', {
  60. 'triple-quoted-string': {
  61. pattern: /"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,
  62. greedy: true,
  63. alias: 'string'
  64. },
  65. 'char': {
  66. pattern: /'(?:\\.|[^'\\\r\n]){1,6}'/,
  67. greedy: true
  68. }
  69. });
  70. Prism.languages.insertBefore('java', 'class-name', {
  71. 'annotation': {
  72. pattern: /(^|[^.])@\w+(?:\s*\.\s*\w+)*/,
  73. lookbehind: true,
  74. alias: 'punctuation'
  75. },
  76. 'generics': {
  77. pattern: /<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,
  78. inside: {
  79. 'class-name': className,
  80. 'keyword': keywords,
  81. 'punctuation': /[<>(),.:]/,
  82. 'operator': /[?&|]/
  83. }
  84. },
  85. 'import': [
  86. {
  87. pattern: RegExp(/(\bimport\s+)/.source + classNamePrefix + /(?:[A-Z]\w*|\*)(?=\s*;)/.source),
  88. lookbehind: true,
  89. inside: {
  90. 'namespace': className.inside.namespace,
  91. 'punctuation': /\./,
  92. 'operator': /\*/,
  93. 'class-name': /\w+/
  94. }
  95. },
  96. {
  97. pattern: RegExp(/(\bimport\s+static\s+)/.source + classNamePrefix + /(?:\w+|\*)(?=\s*;)/.source),
  98. lookbehind: true,
  99. alias: 'static',
  100. inside: {
  101. 'namespace': className.inside.namespace,
  102. 'static': /\b\w+$/,
  103. 'punctuation': /\./,
  104. 'operator': /\*/,
  105. 'class-name': /\w+/
  106. }
  107. }
  108. ],
  109. 'namespace': {
  110. pattern: RegExp(/(\b(?:exports|import(?:\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\s+)(?!<keyword>)[a-z]\w*(?:\.[a-z]\w*)*\.?/
  111. .source.replace(/<keyword>/g, function () { return keywords.source; })),
  112. lookbehind: true,
  113. inside: {
  114. 'punctuation': /\./
  115. }
  116. }
  117. });
  118. }(Prism));
  119. /* </pre> */