mirror of
https://github.com/go-gitea/gitea
synced 2024-11-10 20:24:24 +00:00
fae07cbc8f
* Add Dependencie Update Script * update gitea.com/lunny/levelqueue * update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-redis/redis/v8 * update github.com/hashicorp/golang-lru * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/olivere/elastic/v7 * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark
74 lines
2.1 KiB
Go
Vendored
74 lines
2.1 KiB
Go
Vendored
package s
|
|
|
|
import (
|
|
. "github.com/alecthomas/chroma" // nolint
|
|
"github.com/alecthomas/chroma/lexers/h"
|
|
"github.com/alecthomas/chroma/lexers/internal"
|
|
"github.com/alecthomas/chroma/lexers/t"
|
|
)
|
|
|
|
// Svelte lexer.
|
|
var Svelte = internal.Register(DelegatingLexer(h.HTML, MustNewLazyLexer(
|
|
&Config{
|
|
Name: "Svelte",
|
|
Aliases: []string{"svelte"},
|
|
Filenames: []string{"*.svelte"},
|
|
MimeTypes: []string{"application/x-svelte"},
|
|
DotAll: true,
|
|
},
|
|
svelteRules,
|
|
)))
|
|
|
|
func svelteRules() Rules {
|
|
return Rules{
|
|
"root": {
|
|
// Let HTML handle the comments, including comments containing script and style tags
|
|
{`<!--`, Other, Push("comment")},
|
|
{
|
|
// Highlight script and style tags based on lang attribute
|
|
// and allow attributes besides lang
|
|
`(<\s*(?:script|style).*?lang\s*=\s*['"])` +
|
|
`(.+?)(['"].*?>)` +
|
|
`(.+?)` +
|
|
`(<\s*/\s*(?:script|style)\s*>)`,
|
|
UsingByGroup(internal.Get, 2, 4, Other, Other, Other, Other, Other),
|
|
nil,
|
|
},
|
|
{
|
|
// Make sure `{` is not inside script or style tags
|
|
`(?<!<\s*(?:script|style)(?:(?!(?:script|style)\s*>).)*?)` +
|
|
`{` +
|
|
`(?!(?:(?!<\s*(?:script|style)).)*?(?:script|style)\s*>)`,
|
|
Punctuation,
|
|
Push("templates"),
|
|
},
|
|
// on:submit|preventDefault
|
|
{`(?<=\s+on:\w+(?:\|\w+)*)\|(?=\w+)`, Operator, nil},
|
|
{`.+?`, Other, nil},
|
|
},
|
|
"comment": {
|
|
{`-->`, Other, Pop(1)},
|
|
{`.+?`, Other, nil},
|
|
},
|
|
"templates": {
|
|
{`}`, Punctuation, Pop(1)},
|
|
// Let TypeScript handle strings and the curly braces inside them
|
|
{`(?<!(?<!\\)\\)(['"` + "`])" + `.*?(?<!(?<!\\)\\)\1`, Using(t.TypeScript), nil},
|
|
// If there is another opening curly brace push to templates again
|
|
{"{", Punctuation, Push("templates")},
|
|
{`@(debug|html)\b`, Keyword, nil},
|
|
{
|
|
`(#await)(\s+)(\w+)(\s+)(then|catch)(\s+)(\w+)`,
|
|
ByGroups(Keyword, Text, Using(t.TypeScript), Text,
|
|
Keyword, Text, Using(t.TypeScript),
|
|
),
|
|
nil,
|
|
},
|
|
{`(#|/)(await|each|if|key)\b`, Keyword, nil},
|
|
{`(:else)(\s+)(if)?\b`, ByGroups(Keyword, Text, Keyword), nil},
|
|
{`:(catch|then)\b`, Keyword, nil},
|
|
{`[^{}]+`, Using(t.TypeScript), nil},
|
|
},
|
|
}
|
|
}
|