mirror of
https://github.com/go-gitea/gitea
synced 2024-11-14 14:14:25 +00: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>
60 lines
2.0 KiB
Go
Vendored
60 lines
2.0 KiB
Go
Vendored
package n
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
)
|
|
|
|
// Nasm lexer.
|
|
var Nasm = internal.Register(MustNewLexer(
|
|
&Config{
|
|
Name: "NASM",
|
|
Aliases: []string{"nasm"},
|
|
Filenames: []string{"*.asm", "*.ASM"},
|
|
MimeTypes: []string{"text/x-nasm"},
|
|
CaseInsensitive: true,
|
|
},
|
|
Rules{
|
|
"root": {
|
|
{`^\s*%`, CommentPreproc, Push("preproc")},
|
|
Include("whitespace"),
|
|
{`[a-z$._?][\w$.?#@~]*:`, NameLabel, nil},
|
|
{`([a-z$._?][\w$.?#@~]*)(\s+)(equ)`, ByGroups(NameConstant, KeywordDeclaration, KeywordDeclaration), Push("instruction-args")},
|
|
{`BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|EXPORT|LIBRARY|MODULE`, Keyword, Push("instruction-args")},
|
|
{`(?:res|d)[bwdqt]|times`, KeywordDeclaration, Push("instruction-args")},
|
|
{`[a-z$._?][\w$.?#@~]*`, NameFunction, Push("instruction-args")},
|
|
{`[\r\n]+`, Text, nil},
|
|
},
|
|
"instruction-args": {
|
|
{"\"(\\\\\"|[^\"\\n])*\"|'(\\\\'|[^'\\n])*'|`(\\\\`|[^`\\n])*`", LiteralString, nil},
|
|
{`(?:0x[0-9a-f]+|$0[0-9a-f]*|[0-9]+[0-9a-f]*h)`, LiteralNumberHex, nil},
|
|
{`[0-7]+q`, LiteralNumberOct, nil},
|
|
{`[01]+b`, LiteralNumberBin, nil},
|
|
{`[0-9]+\.e?[0-9]+`, LiteralNumberFloat, nil},
|
|
{`[0-9]+`, LiteralNumberInteger, nil},
|
|
Include("punctuation"),
|
|
{`r[0-9][0-5]?[bwd]|[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]`, NameBuiltin, nil},
|
|
{`[a-z$._?][\w$.?#@~]*`, NameVariable, nil},
|
|
{`[\r\n]+`, Text, Pop(1)},
|
|
Include("whitespace"),
|
|
},
|
|
"preproc": {
|
|
{`[^;\n]+`, CommentPreproc, nil},
|
|
{`;.*?\n`, CommentSingle, Pop(1)},
|
|
{`\n`, CommentPreproc, Pop(1)},
|
|
},
|
|
"whitespace": {
|
|
{`\n`, Text, nil},
|
|
{`[ \t]+`, Text, nil},
|
|
{`;.*`, CommentSingle, nil},
|
|
},
|
|
"punctuation": {
|
|
{`[,():\[\]]+`, Punctuation, nil},
|
|
{`[&|^<>+*/%~-]+`, Operator, nil},
|
|
{`[$]+`, KeywordConstant, nil},
|
|
{`seg|wrt|strict`, OperatorWord, nil},
|
|
{`byte|[dq]?word`, KeywordType, nil},
|
|
},
|
|
},
|
|
))
|