mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-04 08:17:24 -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>
44 lines
1.9 KiB
Go
Vendored
44 lines
1.9 KiB
Go
Vendored
package o
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
)
|
|
|
|
var OpenSCAD = internal.Register(MustNewLexer(
|
|
&Config{
|
|
Name: "OpenSCAD",
|
|
Aliases: []string{"openscad"},
|
|
Filenames: []string{"*.scad"},
|
|
MimeTypes: []string{"text/x-scad"},
|
|
},
|
|
Rules{
|
|
"root": {
|
|
{`[^\S\n]+`, Text, nil},
|
|
{`\n`, Text, nil},
|
|
{`//(\n|[\w\W]*?[^\\]\n)`, CommentSingle, nil},
|
|
{`/(\\\n)?[*][\w\W]*?[*](\\\n)?/`, CommentMultiline, nil},
|
|
{`/(\\\n)?[*][\w\W]*`, CommentMultiline, nil},
|
|
{`[{}\[\]\(\),;:]`, Punctuation, nil},
|
|
{`[*!#%\-+=?/]`, Operator, nil},
|
|
{`<|<=|==|!=|>=|>|&&|\|\|`, Operator, nil},
|
|
{`\$(f[asn]|t|vp[rtd]|children)`, NameVariableMagic, nil},
|
|
{Words(``, `\b`, `PI`, `undef`), KeywordConstant, nil},
|
|
{`(use|include)((?:\s|\\\\s)+)`, ByGroups(KeywordNamespace, Text), Push("includes")},
|
|
{`(module)(\s*)([^\s\(]+)`, ByGroups(KeywordNamespace, Text, NameNamespace), nil},
|
|
{`(function)(\s*)([^\s\(]+)`, ByGroups(KeywordDeclaration, Text, NameFunction), nil},
|
|
{`\b(true|false)\b`, Literal, nil},
|
|
{`\b(function|module|include|use|for|intersection_for|if|else|return)\b`, Keyword, nil},
|
|
{`\b(circle|square|polygon|text|sphere|cube|cylinder|polyhedron|translate|rotate|scale|resize|mirror|multmatrix|color|offset|hull|minkowski|union|difference|intersection|abs|sign|sin|cos|tan|acos|asin|atan|atan2|floor|round|ceil|ln|log|pow|sqrt|exp|rands|min|max|concat|lookup|str|chr|search|version|version_num|norm|cross|parent_module|echo|import|import_dxf|dxf_linear_extrude|linear_extrude|rotate_extrude|surface|projection|render|dxf_cross|dxf_dim|let|assign|len)\b`, NameBuiltin, nil},
|
|
{`\bchildren\b`, NameBuiltinPseudo, nil},
|
|
{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
|
|
{`-?\d+(\.\d+)?(e[+-]?\d+)?`, Number, nil},
|
|
{`[a-zA-Z_]\w*`, Name, nil},
|
|
},
|
|
"includes": {
|
|
{"(<)([^>]*)(>)", ByGroups(Punctuation, CommentPreprocFile, Punctuation), nil},
|
|
Default(Pop(1)),
|
|
},
|
|
},
|
|
))
|