summaryrefslogtreecommitdiff
path: root/vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-25 00:47:47 +0200
commitc6cc0108ca7738023b45e0eeac0fa2390532dd93 (patch)
tree36890e6cd3091bbab8efbe686cc56f467f645bfd /vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go
parent0130404a1dc663d4aa68d780c9bcb23a4243e68d (diff)
downloadjbmafp-master.tar.gz
Added vendor lock on depsHEADmaster
Diffstat (limited to 'vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go')
-rw-r--r--vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go b/vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go
new file mode 100644
index 0000000..39211c4
--- /dev/null
+++ b/vendor/github.com/alecthomas/chroma/v2/lexers/svelte.go
@@ -0,0 +1,70 @@
+package lexers
+
+import (
+ . "github.com/alecthomas/chroma/v2" // nolint
+)
+
+// Svelte lexer.
+var Svelte = Register(DelegatingLexer(HTML, MustNewLexer(
+ &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(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("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("TypeScript"), Text,
+ Keyword, Text, Using("TypeScript"),
+ ),
+ nil,
+ },
+ {`(#|/)(await|each|if|key)\b`, Keyword, nil},
+ {`(:else)(\s+)(if)?\b`, ByGroups(Keyword, Text, Keyword), nil},
+ {`:(catch|then)\b`, Keyword, nil},
+ {`[^{}]+`, Using("TypeScript"), nil},
+ },
+ }
+}