mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-14 11:48:09 -05:00
af7ffaa279
* 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>
91 lines
3.2 KiB
Go
Vendored
91 lines
3.2 KiB
Go
Vendored
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},
|
|
},
|
|
},
|
|
))
|