mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 08:47:42 -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>
67 lines
3.1 KiB
Go
Vendored
67 lines
3.1 KiB
Go
Vendored
package y
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
)
|
|
|
|
var YANG = internal.Register(MustNewLexer(
|
|
&Config{
|
|
Name: "YANG",
|
|
Aliases: []string{"yang"},
|
|
Filenames: []string{"*.yang"},
|
|
MimeTypes: []string{"application/yang"},
|
|
},
|
|
Rules{
|
|
"root": {
|
|
{`\s+`, Whitespace, nil},
|
|
{`[\{\}\;]+`, Punctuation, nil},
|
|
{`(?<![\-\w])(and|or|not|\+|\.)(?![\-\w])`, Operator, nil},
|
|
|
|
{`"(?:\\"|[^"])*?"`, StringDouble, nil},
|
|
{`'(?:\\'|[^'])*?'`, StringSingle, nil},
|
|
|
|
{`/\*`, CommentMultiline, Push("comments")},
|
|
{`//.*?$`, CommentSingle, nil},
|
|
|
|
//match BNF stmt for `node-identifier` with [ prefix ":"]
|
|
{`(?:^|(?<=[\s{};]))([\w.-]+)(:)([\w.-]+)(?=[\s{};])`, ByGroups(KeywordNamespace, Punctuation, Text), nil},
|
|
|
|
//match BNF stmt `date-arg-str`
|
|
{`([0-9]{4}\-[0-9]{2}\-[0-9]{2})(?=[\s\{\}\;])`, LiteralDate, nil},
|
|
{`([0-9]+\.[0-9]+)(?=[\s\{\}\;])`, NumberFloat, nil},
|
|
{`([0-9]+)(?=[\s\{\}\;])`, NumberInteger, nil},
|
|
|
|
//TOP_STMTS_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `module`, `submodule`), Keyword, nil},
|
|
//MODULE_HEADER_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `belongs-to`, `namespace`, `prefix`, `yang-version`), Keyword, nil},
|
|
//META_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `contact`, `description`, `organization`, `reference`, `revision`), Keyword, nil},
|
|
//LINKAGE_STMTS_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `import`, `include`, `revision-date`), Keyword, nil},
|
|
//BODY_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `action`, `argument`, `augment`, `deviation`, `extension`, `feature`, `grouping`, `identity`, `if-feature`, `input`, `notification`, `output`, `rpc`, `typedef`), Keyword, nil},
|
|
//DATA_DEF_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `anydata`, `anyxml`, `case`, `choice`, `config`, `container`, `deviate`, `leaf`, `leaf-list`, `list`, `must`, `presence`, `refine`, `uses`, `when`), Keyword, nil},
|
|
//TYPE_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `base`, `bit`, `default`, `enum`, `error-app-tag`, `error-message`, `fraction-digits`, `length`, `max-elements`, `min-elements`, `modifier`, `ordered-by`, `path`, `pattern`, `position`, `range`, `require-instance`, `status`, `type`, `units`, `value`, `yin-element`), Keyword, nil},
|
|
//LIST_STMT_KEYWORDS
|
|
{Words(``, `(?=[^\w\-\:])`, `key`, `mandatory`, `unique`), Keyword, nil},
|
|
|
|
//CONSTANTS_KEYWORDS - RFC7950 other keywords
|
|
{Words(``, `(?=[^\w\-\:])`, `add`, `current`, `delete`, `deprecated`, `false`, `invert-match`, `max`, `min`, `not-supported`, `obsolete`, `replace`, `true`, `unbounded`, `user`), NameClass, nil},
|
|
|
|
//RFC7950 Built-In Types
|
|
{Words(``, `(?=[^\w\-\:])`, `binary`, `bits`, `boolean`, `decimal64`, `empty`, `enumeration`, `identityref`, `instance-identifier`, `int16`, `int32`, `int64`, `int8`, `leafref`, `string`, `uint16`, `uint32`, `uint64`, `uint8`, `union`), NameClass, nil},
|
|
|
|
{`[^;{}\s\'\"]+`, Text, nil},
|
|
},
|
|
"comments": {
|
|
{`[^*/]`, CommentMultiline, nil},
|
|
{`/\*`, CommentMultiline, Push("comment")},
|
|
{`\*/`, CommentMultiline, Pop(1)},
|
|
{`[*/]`, CommentMultiline, nil},
|
|
},
|
|
},
|
|
))
|