MediaWiki:Gadget-prism-language-python.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-python/Gadget-prism-language-python.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. Prism.languages.python = {
  10. 'comment': {
  11. pattern: /(^|[^\\])#.*/,
  12. lookbehind: true,
  13. greedy: true
  14. },
  15. 'string-interpolation': {
  16. pattern: /(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,
  17. greedy: true,
  18. inside: {
  19. 'interpolation': {
  20. pattern: /((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,
  21. lookbehind: true,
  22. inside: {
  23. 'format-spec': {
  24. pattern: /(:)[^:(){}]+(?=\}$)/,
  25. lookbehind: true
  26. },
  27. 'conversion-option': {
  28. pattern: /![sra](?=[:}]$)/,
  29. alias: 'punctuation'
  30. },
  31. rest: null
  32. }
  33. },
  34. 'string': /[\s\S]+/
  35. }
  36. },
  37. 'triple-quoted-string': {
  38. pattern: /(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,
  39. greedy: true,
  40. alias: 'string'
  41. },
  42. 'string': {
  43. pattern: /(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,
  44. greedy: true
  45. },
  46. 'function': {
  47. pattern: /((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,
  48. lookbehind: true
  49. },
  50. 'class-name': {
  51. pattern: /(\bclass\s+)\w+/i,
  52. lookbehind: true
  53. },
  54. 'decorator': {
  55. pattern: /(^[\t ]*)@\w+(?:\.\w+)*/m,
  56. lookbehind: true,
  57. alias: ['annotation', 'punctuation'],
  58. inside: {
  59. 'punctuation': /\./
  60. }
  61. },
  62. 'keyword': /\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,
  63. 'builtin': /\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,
  64. 'boolean': /\b(?:False|None|True)\b/,
  65. 'number': /\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,
  66. 'operator': /[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,
  67. 'punctuation': /[{}[\];(),.:]/
  68. };
  69. Prism.languages.python['string-interpolation'].inside['interpolation'].inside.rest = Prism.languages.python;
  70. Prism.languages.py = Prism.languages.python;
  71. /* </pre> */