0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-19 16:31:41 +01:00
gitea/vendor/github.com/alecthomas/chroma/lexers/p/powershell.go
mrsdizzie af7ffaa279
Server-side syntax highlighting for all code (#12047)
* Server-side syntax hilighting for all code

This PR does a few things:

* Remove all traces of highlight.js
* Use chroma library to provide fast syntax hilighting directly on the server
* Provide syntax hilighting for diffs
* Re-style both unified and split diffs views
* Add custom syntax hilighting styling for both regular and arc-green

Fixes #7729
Fixes #10157
Fixes #11825
Fixes #7728
Fixes #3872
Fixes #3682

And perhaps gets closer to #9553

* fix line marker

* fix repo search

* Fix single line select

* properly load settings

* npm uninstall highlight.js

* review suggestion

* code review

* forgot to call function

* fix test

* Apply suggestions from code review

suggestions from @silverwind thanks

Co-authored-by: silverwind <me@silverwind.io>

* code review

* copy/paste error

* Use const for highlight size limit

* Update web_src/less/_repository.less

Co-authored-by: Lauris BH <lauris@nix.lv>

* update size limit to 1MB and other styling tweaks

* fix highlighting for certain diff sections

* fix test

* add worker back as suggested

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lauris BH <lauris@nix.lv>
2020-07-01 00:34:03 +03:00

66 lines
4.4 KiB
Go
Vendored

package p
import (
. "github.com/alecthomas/chroma" // nolint
"github.com/alecthomas/chroma/lexers/internal"
)
// Powershell lexer.
var Powershell = internal.Register(MustNewLexer(
&Config{
Name: "PowerShell",
Aliases: []string{"powershell", "posh", "ps1", "psm1"},
Filenames: []string{"*.ps1", "*.psm1"},
MimeTypes: []string{"text/x-powershell"},
DotAll: true,
CaseInsensitive: true,
},
Rules{
"root": {
{`\(`, Punctuation, Push("child")},
{`\s+`, Text, nil},
{`^(\s*#[#\s]*)(\.(?:component|description|example|externalhelp|forwardhelpcategory|forwardhelptargetname|functionality|inputs|link|notes|outputs|parameter|remotehelprunspace|role|synopsis))([^\n]*$)`, ByGroups(Comment, LiteralStringDoc, Comment), nil},
{`#[^\n]*?$`, Comment, nil},
{`(&lt;|<)#`, CommentMultiline, Push("multline")},
{`(?i)([A-Z]:)`, Name, nil},
{`@"\n`, LiteralStringHeredoc, Push("heredoc-double")},
{`@'\n.*?\n'@`, LiteralStringHeredoc, nil},
{"`[\\'\"$@-]", Punctuation, nil},
{`"`, LiteralStringDouble, Push("string")},
{`'([^']|'')*'`, LiteralStringSingle, nil},
{`(\$|@@|@)((global|script|private|env):)?\w+`, NameVariable, nil},
{`(while|validateset|validaterange|validatepattern|validatelength|validatecount|until|trap|switch|return|ref|process|param|parameter|in|if|global:|function|foreach|for|finally|filter|end|elseif|else|dynamicparam|do|default|continue|cmdletbinding|break|begin|alias|\?|%|#script|#private|#local|#global|mandatory|parametersetname|position|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|helpmessage|try|catch|throw)\b`, Keyword, nil},
{`-(and|as|band|bnot|bor|bxor|casesensitive|ccontains|ceq|cge|cgt|cle|clike|clt|cmatch|cne|cnotcontains|cnotlike|cnotmatch|contains|creplace|eq|exact|f|file|ge|gt|icontains|ieq|ige|igt|ile|ilike|ilt|imatch|ine|inotcontains|inotlike|inotmatch|ireplace|is|isnot|le|like|lt|match|ne|not|notcontains|notlike|notmatch|or|regex|replace|wildcard)\b`, Operator, nil},
{`(write|where|watch|wait|use|update|unregister|unpublish|unprotect|unlock|uninstall|undo|unblock|trace|test|tee|take|sync|switch|suspend|submit|stop|step|start|split|sort|skip|show|set|send|select|search|scroll|save|revoke|resume|restore|restart|resolve|resize|reset|request|repair|rename|remove|register|redo|receive|read|push|publish|protect|pop|ping|out|optimize|open|new|move|mount|merge|measure|lock|limit|join|invoke|install|initialize|import|hide|group|grant|get|format|foreach|find|export|expand|exit|enter|enable|edit|dismount|disconnect|disable|deny|debug|cxnew|copy|convertto|convertfrom|convert|connect|confirm|compress|complete|compare|close|clear|checkpoint|block|backup|assert|approve|aggregate|add)-[a-z_]\w*\b`, NameBuiltin, nil},
{`(ac|asnp|cat|cd|cfs|chdir|clc|clear|clhy|cli|clp|cls|clv|cnsn|compare|copy|cp|cpi|cpp|curl|cvpa|dbp|del|diff|dir|dnsn|ebp|echo|epal|epcsv|epsn|erase|etsn|exsn|fc|fhx|fl|foreach|ft|fw|gal|gbp|gc|gci|gcm|gcs|gdr|ghy|gi|gjb|gl|gm|gmo|gp|gps|gpv|group|gsn|gsnp|gsv|gu|gv|gwmi|h|history|icm|iex|ihy|ii|ipal|ipcsv|ipmo|ipsn|irm|ise|iwmi|iwr|kill|lp|ls|man|md|measure|mi|mount|move|mp|mv|nal|ndr|ni|nmo|npssc|nsn|nv|ogv|oh|popd|ps|pushd|pwd|r|rbp|rcjb|rcsn|rd|rdr|ren|ri|rjb|rm|rmdir|rmo|rni|rnp|rp|rsn|rsnp|rujb|rv|rvpa|rwmi|sajb|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spjb|spps|spsv|start|sujb|sv|swmi|tee|trcm|type|wget|where|wjb|write)\s`, NameBuiltin, nil},
{"\\[[a-z_\\[][\\w. `,\\[\\]]*\\]", NameConstant, nil},
{`-[a-z_]\w*`, Name, nil},
{`\w+`, Name, nil},
{"[.,;@{}\\[\\]$()=+*/\\\\&%!~?^`|<>-]|::", Punctuation, nil},
},
"child": {
{`\)`, Punctuation, Pop(1)},
Include("root"),
},
"multline": {
{`[^#&.]+`, CommentMultiline, nil},
{`#(>|&gt;)`, CommentMultiline, Pop(1)},
{`\.(component|description|example|externalhelp|forwardhelpcategory|forwardhelptargetname|functionality|inputs|link|notes|outputs|parameter|remotehelprunspace|role|synopsis)`, LiteralStringDoc, nil},
{`[#&.]`, CommentMultiline, nil},
},
"string": {
{"`[0abfnrtv'\\\"$`]", LiteralStringEscape, nil},
{"[^$`\"]+", LiteralStringDouble, nil},
{`\$\(`, Punctuation, Push("child")},
{`""`, LiteralStringDouble, nil},
{"[`$]", LiteralStringDouble, nil},
{`"`, LiteralStringDouble, Pop(1)},
},
"heredoc-double": {
{`\n"@`, LiteralStringHeredoc, Pop(1)},
{`\$\(`, Punctuation, Push("child")},
{`[^@\n]+"]`, LiteralStringHeredoc, nil},
{`.`, LiteralStringHeredoc, nil},
},
},
))