mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-04 14:46:57 -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>
61 lines
3.3 KiB
Go
Vendored
61 lines
3.3 KiB
Go
Vendored
package t
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
)
|
|
|
|
// Terraform lexer.
|
|
var Terraform = internal.Register(MustNewLexer(
|
|
&Config{
|
|
Name: "Terraform",
|
|
Aliases: []string{"terraform", "tf"},
|
|
Filenames: []string{"*.tf"},
|
|
MimeTypes: []string{"application/x-tf", "application/x-terraform"},
|
|
},
|
|
Rules{
|
|
"root": {
|
|
{`[\[\](),.{}]`, Punctuation, nil},
|
|
{`-?[0-9]+`, LiteralNumber, nil},
|
|
{`=>`, Punctuation, nil},
|
|
{Words(``, `\b`, `true`, `false`), KeywordConstant, nil},
|
|
{`/(?s)\*(((?!\*/).)*)\*/`, CommentMultiline, nil},
|
|
{`\s*(#|//).*\n`, CommentSingle, nil},
|
|
{`([a-zA-Z]\w*)(\s*)(=(?!>))`, ByGroups(NameAttribute, Text, Text), nil},
|
|
{Words(`^\s*`, `\b`, `variable`, `data`, `resource`, `provider`, `provisioner`, `module`, `output`), KeywordReserved, nil},
|
|
{Words(``, `\b`, `for`, `in`), Keyword, nil},
|
|
{Words(``, ``, `count`, `data`, `var`, `module`, `each`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `abs`, `ceil`, `floor`, `log`, `max`, `min`, `parseint`, `pow`, `signum`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `chomp`, `format`, `formatlist`, `indent`, `join`, `lower`, `regex`, `regexall`, `replace`, `split`, `strrev`, `substr`, `title`, `trim`, `trimprefix`, `trimsuffix`, `trimspace`, `upper`), NameBuiltin, nil},
|
|
{Words(`[^.]`, `\b`, `chunklist`, `coalesce`, `coalescelist`, `compact`, `concat`, `contains`, `distinct`, `element`, `flatten`, `index`, `keys`, `length`, `list`, `lookup`, `map`, `matchkeys`, `merge`, `range`, `reverse`, `setintersection`, `setproduct`, `setsubtract`, `setunion`, `slice`, `sort`, `transpose`, `values`, `zipmap`), NameBuiltin, nil},
|
|
{Words(`[^.]`, `\b`, `base64decode`, `base64encode`, `base64gzip`, `csvdecode`, `jsondecode`, `jsonencode`, `urlencode`, `yamldecode`, `yamlencode`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `abspath`, `dirname`, `pathexpand`, `basename`, `file`, `fileexists`, `fileset`, `filebase64`, `templatefile`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `formatdate`, `timeadd`, `timestamp`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `base64sha256`, `base64sha512`, `bcrypt`, `filebase64sha256`, `filebase64sha512`, `filemd5`, `filesha1`, `filesha256`, `filesha512`, `md5`, `rsadecrypt`, `sha1`, `sha256`, `sha512`, `uuid`, `uuidv5`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `cidrhost`, `cidrnetmask`, `cidrsubnet`), NameBuiltin, nil},
|
|
{Words(``, `\b`, `can`, `tobool`, `tolist`, `tomap`, `tonumber`, `toset`, `tostring`, `try`), NameBuiltin, nil},
|
|
{`=(?!>)|\+|-|\*|\/|:|!|%|>|<(?!<)|>=|<=|==|!=|&&|\||\?`, Operator, nil},
|
|
{`\n|\s+|\\\n`, Text, nil},
|
|
{`[a-zA-Z]\w*`, NameOther, nil},
|
|
{`"`, LiteralStringDouble, Push("string")},
|
|
{`(?s)(<<-?)(\w+)(\n\s*(?:(?!\2).)*\s*\n\s*)(\2)`, ByGroups(Operator, Operator, String, Operator), nil},
|
|
},
|
|
"declaration": {
|
|
{`(\s*)("(?:\\\\|\\"|[^"])*")(\s*)`, ByGroups(Text, NameVariable, Text), nil},
|
|
{`\{`, Punctuation, Pop(1)},
|
|
},
|
|
"string": {
|
|
{`"`, LiteralStringDouble, Pop(1)},
|
|
{`\\\\`, LiteralStringDouble, nil},
|
|
{`\\\\"`, LiteralStringDouble, nil},
|
|
{`\$\{`, LiteralStringInterpol, Push("interp-inside")},
|
|
{`\$`, LiteralStringDouble, nil},
|
|
{`[^"\\\\$]+`, LiteralStringDouble, nil},
|
|
},
|
|
"interp-inside": {
|
|
{`\}`, LiteralStringInterpol, Pop(1)},
|
|
Include("root"),
|
|
},
|
|
},
|
|
))
|