mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 22:43:56 +08:00
904275a8f1
It was at ~10.7.0 (`7f3240ea`) in tests and 10.6.0 (`eb122d3b`) in production build before… So my #14908 broke the build.
40 lines
3.3 KiB
JavaScript
40 lines
3.3 KiB
JavaScript
hljs.registerLanguage("python",(()=>{"use strict";return e=>{const n={
|
|
$pattern:/[A-Za-z]\w+|__\w+__/,
|
|
keyword:["and","as","assert","async","await","break","class","continue","def","del","elif","else","except","finally","for","from","global","if","import","in","is","lambda","nonlocal|10","not","or","pass","raise","return","try","while","with","yield"],
|
|
built_in:["__import__","abs","all","any","ascii","bin","bool","breakpoint","bytearray","bytes","callable","chr","classmethod","compile","complex","delattr","dict","dir","divmod","enumerate","eval","exec","filter","float","format","frozenset","getattr","globals","hasattr","hash","help","hex","id","input","int","isinstance","issubclass","iter","len","list","locals","map","max","memoryview","min","next","object","oct","open","ord","pow","print","property","range","repr","reversed","round","set","setattr","slice","sorted","staticmethod","str","sum","super","tuple","type","vars","zip"],
|
|
literal:["__debug__","Ellipsis","False","None","NotImplemented","True"],
|
|
type:["Any","Callable","Coroutine","Dict","List","Literal","Generic","Optional","Sequence","Set","Tuple","Type","Union"]
|
|
},a={className:"meta",begin:/^(>>>|\.\.\.) /},i={className:"subst",begin:/\{/,
|
|
end:/\}/,keywords:n,illegal:/#/},s={begin:/\{\{/,relevance:0},t={
|
|
className:"string",contains:[e.BACKSLASH_ESCAPE],variants:[{
|
|
begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?'''/,end:/'''/,
|
|
contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{
|
|
begin:/([uU]|[bB]|[rR]|[bB][rR]|[rR][bB])?"""/,end:/"""/,
|
|
contains:[e.BACKSLASH_ESCAPE,a],relevance:10},{
|
|
begin:/([fF][rR]|[rR][fF]|[fF])'''/,end:/'''/,
|
|
contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/([fF][rR]|[rR][fF]|[fF])"""/,
|
|
end:/"""/,contains:[e.BACKSLASH_ESCAPE,a,s,i]},{begin:/([uU]|[rR])'/,end:/'/,
|
|
relevance:10},{begin:/([uU]|[rR])"/,end:/"/,relevance:10},{
|
|
begin:/([bB]|[bB][rR]|[rR][bB])'/,end:/'/},{begin:/([bB]|[bB][rR]|[rR][bB])"/,
|
|
end:/"/},{begin:/([fF][rR]|[rR][fF]|[fF])'/,end:/'/,
|
|
contains:[e.BACKSLASH_ESCAPE,s,i]},{begin:/([fF][rR]|[rR][fF]|[fF])"/,end:/"/,
|
|
contains:[e.BACKSLASH_ESCAPE,s,i]},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]
|
|
},r="[0-9](_?[0-9])*",l=`(\\b(${r}))?\\.(${r})|\\b(${r})\\.`,b={
|
|
className:"number",relevance:0,variants:[{
|
|
begin:`(\\b(${r})|(${l}))[eE][+-]?(${r})[jJ]?\\b`},{begin:`(${l})[jJ]?`},{
|
|
begin:"\\b([1-9](_?[0-9])*|0+(_?0)*)[lLjJ]?\\b"},{
|
|
begin:"\\b0[bB](_?[01])+[lL]?\\b"},{begin:"\\b0[oO](_?[0-7])+[lL]?\\b"},{
|
|
begin:"\\b0[xX](_?[0-9a-fA-F])+[lL]?\\b"},{begin:`\\b(${r})[jJ]\\b`}]},o={
|
|
className:"comment",
|
|
begin:(d=/# type:/,((...e)=>e.map((e=>(e=>e?"string"==typeof e?e:e.source:null)(e))).join(""))("(?=",d,")")),
|
|
end:/$/,keywords:n,contains:[{begin:/# type:/},{begin:/#/,end:/\b\B/,
|
|
endsWithParent:!0}]},c={className:"params",variants:[{className:"",
|
|
begin:/\(\s*\)/,skip:!0},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,
|
|
keywords:n,contains:["self",a,b,t,e.HASH_COMMENT_MODE]}]};var d
|
|
;return i.contains=[t,b,a],{name:"Python",aliases:["py","gyp","ipython"],
|
|
keywords:n,illegal:/(<\/|->|\?)|=>/,contains:[a,b,{begin:/\bself\b/},{
|
|
beginKeywords:"if",relevance:0},t,o,e.HASH_COMMENT_MODE,{variants:[{
|
|
className:"function",beginKeywords:"def"},{className:"class",
|
|
beginKeywords:"class"}],end:/:/,illegal:/[${=;\n,]/,
|
|
contains:[e.UNDERSCORE_TITLE_MODE,c,{begin:/->/,endsWithParent:!0,keywords:n}]
|
|
},{className:"meta",begin:/^[\t ]*@/,end:/(?=#)|$/,contains:[b,c,t]}]}}})()); |