forked from forgejo/forgejo
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>
This commit is contained in:
parent
ce5f2b9845
commit
af7ffaa279
336 changed files with 37293 additions and 769 deletions
69
vendor/github.com/alecthomas/chroma/lexers/d/d.go
generated
vendored
Normal file
69
vendor/github.com/alecthomas/chroma/lexers/d/d.go
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// D lexer. https://dlang.org/spec/lex.html
|
||||
var D = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "D",
|
||||
Aliases: []string{"d"},
|
||||
Filenames: []string{"*.d", "*.di"},
|
||||
MimeTypes: []string{"text/x-d"},
|
||||
EnsureNL: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`[^\S\n]+`, Text, nil},
|
||||
|
||||
// https://dlang.org/spec/lex.html#comment
|
||||
{`//.*?\n`, CommentSingle, nil},
|
||||
{`/\*.*?\*/`, CommentMultiline, nil},
|
||||
{`/\+.*?\+/`, CommentMultiline, nil},
|
||||
|
||||
// https://dlang.org/spec/lex.html#keywords
|
||||
{`(asm|assert|body|break|case|cast|catch|continue|default|debug|delete|deprecated|do|else|finally|for|foreach|foreach_reverse|goto|if|in|invariant|is|macro|mixin|new|out|pragma|return|super|switch|this|throw|try|version|while|with)\b`, Keyword, nil},
|
||||
{`__(FILE|FILE_FULL_PATH|MODULE|LINE|FUNCTION|PRETTY_FUNCTION|DATE|EOF|TIME|TIMESTAMP|VENDOR|VERSION)__\b`, NameBuiltin, nil},
|
||||
{`__(traits|vector|parameters)\b`, NameBuiltin, nil},
|
||||
{`((?:(?:[^\W\d]|\$)[\w.\[\]$<>]*\s+)+?)((?:[^\W\d]|\$)[\w$]*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
|
||||
|
||||
// https://dlang.org/spec/attribute.html#uda
|
||||
{`@[\w.]*`, NameDecorator, nil},
|
||||
{`(abstract|auto|alias|align|const|delegate|enum|export|final|function|inout|lazy|nothrow|override|package|private|protected|public|pure|static|synchronized|template|volatile|__gshared)\b`, KeywordDeclaration, nil},
|
||||
|
||||
// https://dlang.org/spec/type.html#basic-data-types
|
||||
{`(void|bool|byte|ubyte|short|ushort|int|uint|long|ulong|cent|ucent|float|double|real|ifloat|idouble|ireal|cfloat|cdouble|creal|char|wchar|dchar|string|wstring|dstring)\b`, KeywordType, nil},
|
||||
{`(module)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
|
||||
{`(true|false|null)\b`, KeywordConstant, nil},
|
||||
{`(class|interface|struct|template|union)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
|
||||
{`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
|
||||
|
||||
// https://dlang.org/spec/lex.html#string_literals
|
||||
// TODO support delimited strings
|
||||
{`[qr]?"(\\\\|\\"|[^"])*"[cwd]?`, LiteralString, nil},
|
||||
{"(`)([^`]*)(`)[cwd]?", LiteralString, nil},
|
||||
{`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
|
||||
{`(\.)((?:[^\W\d]|\$)[\w$]*)`, ByGroups(Operator, NameAttribute), nil},
|
||||
{`^\s*([^\W\d]|\$)[\w$]*:`, NameLabel, nil},
|
||||
|
||||
// https://dlang.org/spec/lex.html#floatliteral
|
||||
{`([0-9][0-9_]*\.([0-9][0-9_]*)?|\.[0-9][0-9_]*)([eE][+\-]?[0-9][0-9_]*)?[fFL]?i?|[0-9][eE][+\-]?[0-9][0-9_]*[fFL]?|[0-9]([eE][+\-]?[0-9][0-9_]*)?[fFL]|0[xX]([0-9a-fA-F][0-9a-fA-F_]*\.?|([0-9a-fA-F][0-9a-fA-F_]*)?\.[0-9a-fA-F][0-9a-fA-F_]*)[pP][+\-]?[0-9][0-9_]*[fFL]?`, LiteralNumberFloat, nil},
|
||||
// https://dlang.org/spec/lex.html#integerliteral
|
||||
{`0[xX][0-9a-fA-F][0-9a-fA-F_]*[lL]?`, LiteralNumberHex, nil},
|
||||
{`0[bB][01][01_]*[lL]?`, LiteralNumberBin, nil},
|
||||
{`0[0-7_]+[lL]?`, LiteralNumberOct, nil},
|
||||
{`0|[1-9][0-9_]*[lL]?`, LiteralNumberInteger, nil},
|
||||
{`([~^*!%&\[\](){}<>|+=:;,./?-]|q{)`, Operator, nil},
|
||||
{`([^\W\d]|\$)[\w$]*`, Name, nil},
|
||||
{`\n`, Text, nil},
|
||||
},
|
||||
"class": {
|
||||
{`([^\W\d]|\$)[\w$]*`, NameClass, Pop(1)},
|
||||
},
|
||||
"import": {
|
||||
{`[\w.]+\*?`, NameNamespace, Pop(1)},
|
||||
},
|
||||
},
|
||||
))
|
91
vendor/github.com/alecthomas/chroma/lexers/d/dart.go
generated
vendored
Normal file
91
vendor/github.com/alecthomas/chroma/lexers/d/dart.go
generated
vendored
Normal file
|
@ -0,0 +1,91 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// Dart lexer.
|
||||
var Dart = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "Dart",
|
||||
Aliases: []string{"dart"},
|
||||
Filenames: []string{"*.dart"},
|
||||
MimeTypes: []string{"text/x-dart"},
|
||||
DotAll: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
Include("string_literal"),
|
||||
{`#!(.*?)$`, CommentPreproc, nil},
|
||||
{`\b(import|export)\b`, Keyword, Push("import_decl")},
|
||||
{`\b(library|source|part of|part)\b`, Keyword, nil},
|
||||
{`[^\S\n]+`, Text, nil},
|
||||
{`//.*?\n`, CommentSingle, nil},
|
||||
{`/\*.*?\*/`, CommentMultiline, nil},
|
||||
{`\b(class)\b(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
|
||||
{`\b(assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\b`, Keyword, nil},
|
||||
{`\b(abstract|async|await|const|extends|factory|final|get|implements|native|operator|set|static|sync|typedef|var|with|yield)\b`, KeywordDeclaration, nil},
|
||||
{`\b(bool|double|dynamic|int|num|Object|String|void)\b`, KeywordType, nil},
|
||||
{`\b(false|null|true)\b`, KeywordConstant, nil},
|
||||
{`[~!%^&*+=|?:<>/-]|as\b`, Operator, nil},
|
||||
{`[a-zA-Z_$]\w*:`, NameLabel, nil},
|
||||
{`[a-zA-Z_$]\w*`, Name, nil},
|
||||
{`[(){}\[\],.;]`, Punctuation, nil},
|
||||
{`0[xX][0-9a-fA-F]+`, LiteralNumberHex, nil},
|
||||
{`\d+(\.\d*)?([eE][+-]?\d+)?`, LiteralNumber, nil},
|
||||
{`\.\d+([eE][+-]?\d+)?`, LiteralNumber, nil},
|
||||
{`\n`, Text, nil},
|
||||
},
|
||||
"class": {
|
||||
{`[a-zA-Z_$]\w*`, NameClass, Pop(1)},
|
||||
},
|
||||
"import_decl": {
|
||||
Include("string_literal"),
|
||||
{`\s+`, Text, nil},
|
||||
{`\b(as|show|hide)\b`, Keyword, nil},
|
||||
{`[a-zA-Z_$]\w*`, Name, nil},
|
||||
{`\,`, Punctuation, nil},
|
||||
{`\;`, Punctuation, Pop(1)},
|
||||
},
|
||||
"string_literal": {
|
||||
{`r"""([\w\W]*?)"""`, LiteralStringDouble, nil},
|
||||
{`r'''([\w\W]*?)'''`, LiteralStringSingle, nil},
|
||||
{`r"(.*?)"`, LiteralStringDouble, nil},
|
||||
{`r'(.*?)'`, LiteralStringSingle, nil},
|
||||
{`"""`, LiteralStringDouble, Push("string_double_multiline")},
|
||||
{`'''`, LiteralStringSingle, Push("string_single_multiline")},
|
||||
{`"`, LiteralStringDouble, Push("string_double")},
|
||||
{`'`, LiteralStringSingle, Push("string_single")},
|
||||
},
|
||||
"string_common": {
|
||||
{`\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]*\}|[a-z'\"$\\])`, LiteralStringEscape, nil},
|
||||
{`(\$)([a-zA-Z_]\w*)`, ByGroups(LiteralStringInterpol, Name), nil},
|
||||
{`(\$\{)(.*?)(\})`, ByGroups(LiteralStringInterpol, UsingSelf("root"), LiteralStringInterpol), nil},
|
||||
},
|
||||
"string_double": {
|
||||
{`"`, LiteralStringDouble, Pop(1)},
|
||||
{`[^"$\\\n]+`, LiteralStringDouble, nil},
|
||||
Include("string_common"),
|
||||
{`\$+`, LiteralStringDouble, nil},
|
||||
},
|
||||
"string_double_multiline": {
|
||||
{`"""`, LiteralStringDouble, Pop(1)},
|
||||
{`[^"$\\]+`, LiteralStringDouble, nil},
|
||||
Include("string_common"),
|
||||
{`(\$|\")+`, LiteralStringDouble, nil},
|
||||
},
|
||||
"string_single": {
|
||||
{`'`, LiteralStringSingle, Pop(1)},
|
||||
{`[^'$\\\n]+`, LiteralStringSingle, nil},
|
||||
Include("string_common"),
|
||||
{`\$+`, LiteralStringSingle, nil},
|
||||
},
|
||||
"string_single_multiline": {
|
||||
{`'''`, LiteralStringSingle, Pop(1)},
|
||||
{`[^\'$\\]+`, LiteralStringSingle, nil},
|
||||
Include("string_common"),
|
||||
{`(\$|\')+`, LiteralStringSingle, nil},
|
||||
},
|
||||
},
|
||||
))
|
29
vendor/github.com/alecthomas/chroma/lexers/d/diff.go
generated
vendored
Normal file
29
vendor/github.com/alecthomas/chroma/lexers/d/diff.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// Diff lexer.
|
||||
var Diff = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "Diff",
|
||||
Aliases: []string{"diff", "udiff"},
|
||||
EnsureNL: true,
|
||||
Filenames: []string{"*.diff", "*.patch"},
|
||||
MimeTypes: []string{"text/x-diff", "text/x-patch"},
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{` .*\n`, Text, nil},
|
||||
{`\+.*\n`, GenericInserted, nil},
|
||||
{`-.*\n`, GenericDeleted, nil},
|
||||
{`!.*\n`, GenericStrong, nil},
|
||||
{`@.*\n`, GenericSubheading, nil},
|
||||
{`([Ii]ndex|diff).*\n`, GenericHeading, nil},
|
||||
{`=.*\n`, GenericHeading, nil},
|
||||
{`.*\n`, Text, nil},
|
||||
},
|
||||
},
|
||||
))
|
53
vendor/github.com/alecthomas/chroma/lexers/d/django.go
generated
vendored
Normal file
53
vendor/github.com/alecthomas/chroma/lexers/d/django.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// Django/Jinja lexer.
|
||||
var DjangoJinja = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "Django/Jinja",
|
||||
Aliases: []string{"django", "jinja"},
|
||||
Filenames: []string{},
|
||||
MimeTypes: []string{"application/x-django-templating", "application/x-jinja"},
|
||||
DotAll: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`[^{]+`, Other, nil},
|
||||
{`\{\{`, CommentPreproc, Push("var")},
|
||||
{`\{[*#].*?[*#]\}`, Comment, nil},
|
||||
{`(\{%)(-?\s*)(comment)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endcomment)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Comment, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
|
||||
{`(\{%)(-?\s*)(raw)(\s*-?)(%\})(.*?)(\{%)(-?\s*)(endraw)(\s*-?)(%\})`, ByGroups(CommentPreproc, Text, Keyword, Text, CommentPreproc, Text, CommentPreproc, Text, Keyword, Text, CommentPreproc), nil},
|
||||
{`(\{%)(-?\s*)(filter)(\s+)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword, Text, NameFunction), Push("block")},
|
||||
{`(\{%)(-?\s*)([a-zA-Z_]\w*)`, ByGroups(CommentPreproc, Text, Keyword), Push("block")},
|
||||
{`\{`, Other, nil},
|
||||
},
|
||||
"varnames": {
|
||||
{`(\|)(\s*)([a-zA-Z_]\w*)`, ByGroups(Operator, Text, NameFunction), nil},
|
||||
{`(is)(\s+)(not)?(\s+)?([a-zA-Z_]\w*)`, ByGroups(Keyword, Text, Keyword, Text, NameFunction), nil},
|
||||
{`(_|true|false|none|True|False|None)\b`, KeywordPseudo, nil},
|
||||
{`(in|as|reversed|recursive|not|and|or|is|if|else|import|with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b`, Keyword, nil},
|
||||
{`(loop|block|super|forloop)\b`, NameBuiltin, nil},
|
||||
{`[a-zA-Z_][\w-]*`, NameVariable, nil},
|
||||
{`\.\w+`, NameVariable, nil},
|
||||
{`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
|
||||
{`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
|
||||
{`([{}()\[\]+\-*/,:~]|[><=]=?)`, Operator, nil},
|
||||
{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
|
||||
},
|
||||
"var": {
|
||||
{`\s+`, Text, nil},
|
||||
{`(-?)(\}\})`, ByGroups(Text, CommentPreproc), Pop(1)},
|
||||
Include("varnames"),
|
||||
},
|
||||
"block": {
|
||||
{`\s+`, Text, nil},
|
||||
{`(-?)(%\})`, ByGroups(Text, CommentPreproc), Pop(1)},
|
||||
Include("varnames"),
|
||||
{`.`, Punctuation, nil},
|
||||
},
|
||||
},
|
||||
))
|
31
vendor/github.com/alecthomas/chroma/lexers/d/docker.go
generated
vendored
Normal file
31
vendor/github.com/alecthomas/chroma/lexers/d/docker.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/b"
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
"github.com/alecthomas/chroma/lexers/j"
|
||||
)
|
||||
|
||||
// Docker lexer.
|
||||
var Docker = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "Docker",
|
||||
Aliases: []string{"docker", "dockerfile"},
|
||||
Filenames: []string{"Dockerfile", "*.docker"},
|
||||
MimeTypes: []string{"text/x-dockerfile-config"},
|
||||
CaseInsensitive: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`#.*`, Comment, nil},
|
||||
{`(ONBUILD)((?:\s*\\?\s*))`, ByGroups(Keyword, Using(b.Bash)), nil},
|
||||
{`(HEALTHCHECK)(((?:\s*\\?\s*)--\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using(b.Bash)), nil},
|
||||
{`(VOLUME|ENTRYPOINT|CMD|SHELL)((?:\s*\\?\s*))(\[.*?\])`, ByGroups(Keyword, Using(b.Bash), Using(j.JSON)), nil},
|
||||
{`(LABEL|ENV|ARG)((?:(?:\s*\\?\s*)\w+=\w+(?:\s*\\?\s*))*)`, ByGroups(Keyword, Using(b.Bash)), nil},
|
||||
{`((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(.*)`, ByGroups(Keyword, LiteralString), nil},
|
||||
{`((?:RUN|CMD|ENTRYPOINT|ENV|ARG|LABEL|ADD|COPY))`, Keyword, nil},
|
||||
{`(.*\\\n)*.+`, Using(b.Bash), nil},
|
||||
},
|
||||
},
|
||||
))
|
69
vendor/github.com/alecthomas/chroma/lexers/d/dtd.go
generated
vendored
Normal file
69
vendor/github.com/alecthomas/chroma/lexers/d/dtd.go
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
package d
|
||||
|
||||
import (
|
||||
. "github.com/alecthomas/chroma" // nolint
|
||||
"github.com/alecthomas/chroma/lexers/internal"
|
||||
)
|
||||
|
||||
// Dtd lexer.
|
||||
var Dtd = internal.Register(MustNewLexer(
|
||||
&Config{
|
||||
Name: "DTD",
|
||||
Aliases: []string{"dtd"},
|
||||
Filenames: []string{"*.dtd"},
|
||||
MimeTypes: []string{"application/xml-dtd"},
|
||||
DotAll: true,
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
Include("common"),
|
||||
{`(<!ELEMENT)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("element")},
|
||||
{`(<!ATTLIST)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("attlist")},
|
||||
{`(<!ENTITY)(\s+)(\S+)`, ByGroups(Keyword, Text, NameEntity), Push("entity")},
|
||||
{`(<!NOTATION)(\s+)(\S+)`, ByGroups(Keyword, Text, NameTag), Push("notation")},
|
||||
{`(<!\[)([^\[\s]+)(\s*)(\[)`, ByGroups(Keyword, NameEntity, Text, Keyword), nil},
|
||||
{`(<!DOCTYPE)(\s+)([^>\s]+)`, ByGroups(Keyword, Text, NameTag), nil},
|
||||
{`PUBLIC|SYSTEM`, KeywordConstant, nil},
|
||||
{`[\[\]>]`, Keyword, nil},
|
||||
},
|
||||
"common": {
|
||||
{`\s+`, Text, nil},
|
||||
{`(%|&)[^;]*;`, NameEntity, nil},
|
||||
{`<!--`, Comment, Push("comment")},
|
||||
{`[(|)*,?+]`, Operator, nil},
|
||||
{`"[^"]*"`, LiteralStringDouble, nil},
|
||||
{`\'[^\']*\'`, LiteralStringSingle, nil},
|
||||
},
|
||||
"comment": {
|
||||
{`[^-]+`, Comment, nil},
|
||||
{`-->`, Comment, Pop(1)},
|
||||
{`-`, Comment, nil},
|
||||
},
|
||||
"element": {
|
||||
Include("common"),
|
||||
{`EMPTY|ANY|#PCDATA`, KeywordConstant, nil},
|
||||
{`[^>\s|()?+*,]+`, NameTag, nil},
|
||||
{`>`, Keyword, Pop(1)},
|
||||
},
|
||||
"attlist": {
|
||||
Include("common"),
|
||||
{`CDATA|IDREFS|IDREF|ID|NMTOKENS|NMTOKEN|ENTITIES|ENTITY|NOTATION`, KeywordConstant, nil},
|
||||
{`#REQUIRED|#IMPLIED|#FIXED`, KeywordConstant, nil},
|
||||
{`xml:space|xml:lang`, KeywordReserved, nil},
|
||||
{`[^>\s|()?+*,]+`, NameAttribute, nil},
|
||||
{`>`, Keyword, Pop(1)},
|
||||
},
|
||||
"entity": {
|
||||
Include("common"),
|
||||
{`SYSTEM|PUBLIC|NDATA`, KeywordConstant, nil},
|
||||
{`[^>\s|()?+*,]+`, NameEntity, nil},
|
||||
{`>`, Keyword, Pop(1)},
|
||||
},
|
||||
"notation": {
|
||||
Include("common"),
|
||||
{`SYSTEM|PUBLIC`, KeywordConstant, nil},
|
||||
{`[^>\s|()?+*,]+`, NameAttribute, nil},
|
||||
{`>`, Keyword, Pop(1)},
|
||||
},
|
||||
},
|
||||
))
|
Loading…
Add table
Add a link
Reference in a new issue