MediaWiki:Gadget-prism-language-ruby.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-ruby/Gadget-prism-language-ruby.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. Prism.languages.ruby = Prism.languages.extend('clike', {
  11. 'comment': {
  12. pattern: /#.*|^=begin\s[\s\S]*?^=end/m,
  13. greedy: true
  14. },
  15. 'class-name': {
  16. pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,
  17. lookbehind: true,
  18. inside: {
  19. 'punctuation': /[.\\]/
  20. }
  21. },
  22. 'keyword': /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,
  23. 'operator': /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,
  24. 'punctuation': /[(){}[\].,;]/
  25. });
  26. Prism.languages.insertBefore('ruby', 'operator', {
  27. 'double-colon': {
  28. pattern: /::/,
  29. alias: 'punctuation'
  30. }
  31. });
  32. var interpolation = {
  33. pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,
  34. lookbehind: true,
  35. inside: {
  36. 'content': {
  37. pattern: /^(#\{)[\s\S]+(?=\}$)/,
  38. lookbehind: true,
  39. inside: Prism.languages.ruby
  40. },
  41. 'delimiter': {
  42. pattern: /^#\{|\}$/,
  43. alias: 'punctuation'
  44. }
  45. }
  46. };
  47. delete Prism.languages.ruby["function"];
  48. var percentExpression = '(?:' + [
  49. /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  50. /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,
  51. /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,
  52. /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,
  53. /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source
  54. ].join('|') + ')';
  55. var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;
  56. Prism.languages.insertBefore('ruby', 'keyword', {
  57. 'regex-literal': [
  58. {
  59. pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source),
  60. greedy: true,
  61. inside: {
  62. 'interpolation': interpolation,
  63. 'regex': /[\s\S]+/
  64. }
  65. },
  66. {
  67. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  68. lookbehind: true,
  69. greedy: true,
  70. inside: {
  71. 'interpolation': interpolation,
  72. 'regex': /[\s\S]+/
  73. }
  74. }
  75. ],
  76. 'variable': /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  77. 'symbol': [
  78. {
  79. pattern: RegExp(/(^|[^:]):/.source + symbolName),
  80. lookbehind: true,
  81. greedy: true
  82. },
  83. {
  84. pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source),
  85. lookbehind: true,
  86. greedy: true
  87. },
  88. ],
  89. 'method-definition': {
  90. pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,
  91. lookbehind: true,
  92. inside: {
  93. 'function': /\b\w+$/,
  94. 'keyword': /^self\b/,
  95. 'class-name': /^\w+/,
  96. 'punctuation': /\./
  97. }
  98. }
  99. });
  100. Prism.languages.insertBefore('ruby', 'string', {
  101. 'string-literal': [
  102. {
  103. pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression),
  104. greedy: true,
  105. inside: {
  106. 'interpolation': interpolation,
  107. 'string': /[\s\S]+/
  108. }
  109. },
  110. {
  111. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  112. greedy: true,
  113. inside: {
  114. 'interpolation': interpolation,
  115. 'string': /[\s\S]+/
  116. }
  117. },
  118. {
  119. pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  120. alias: 'heredoc-string',
  121. greedy: true,
  122. inside: {
  123. 'delimiter': {
  124. pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,
  125. inside: {
  126. 'symbol': /\b\w+/,
  127. 'punctuation': /^<<[-~]?/
  128. }
  129. },
  130. 'interpolation': interpolation,
  131. 'string': /[\s\S]+/
  132. }
  133. },
  134. {
  135. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  136. alias: 'heredoc-string',
  137. greedy: true,
  138. inside: {
  139. 'delimiter': {
  140. pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,
  141. inside: {
  142. 'symbol': /\b\w+/,
  143. 'punctuation': /^<<[-~]?'|'$/
  144. }
  145. },
  146. 'string': /[\s\S]+/
  147. }
  148. }
  149. ],
  150. 'command-literal': [
  151. {
  152. pattern: RegExp(/%x/.source + percentExpression),
  153. greedy: true,
  154. inside: {
  155. 'interpolation': interpolation,
  156. 'command': {
  157. pattern: /[\s\S]+/,
  158. alias: 'string'
  159. }
  160. }
  161. },
  162. {
  163. pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,
  164. greedy: true,
  165. inside: {
  166. 'interpolation': interpolation,
  167. 'command': {
  168. pattern: /[\s\S]+/,
  169. alias: 'string'
  170. }
  171. }
  172. }
  173. ]
  174. });
  175. delete Prism.languages.ruby.string;
  176. Prism.languages.insertBefore('ruby', 'number', {
  177. 'builtin': /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,
  178. 'constant': /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/
  179. });
  180. Prism.languages.rb = Prism.languages.ruby;
  181. }(Prism));
  182. /* </pre> */