-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e86123a
commit cab6ebc
Showing
3 changed files
with
283 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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": { | ||
{`(<\s*script\s*lang\s*=\s*['"](?:ts|typescript)['"]\s*>)(.+?)(<\s*/\s*script\s*>)`, ByGroups(Other, Using(t.TypeScript), Other), nil}, | ||
{`\{`, Punctuation, Push("templates")}, | ||
{`[^{]`, Other, nil}, | ||
}, | ||
"templates": { | ||
{`}`, Punctuation, Pop(1)}, | ||
{`@(debug|html)\b`, Keyword, nil}, | ||
{`(#|/)(await|each|if)\b`, Keyword, nil}, | ||
{`(:else)(\s+)(if)?\b`, ByGroups(Keyword, Text, Keyword), nil}, | ||
{`:(catch|then)\b`, Keyword, nil}, | ||
{`then\b`, Keyword, nil}, | ||
{`[^}]+`, Using(t.TypeScript), nil}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<script lang="typescript"> | ||
// Nested is defined elsewhere | ||
import Nested from './Nested.svelte'; | ||
|
||
let src = 'example.png'; | ||
let name = 'world'; | ||
|
||
let names = [ | ||
{ id: 'id0001', name: 'Name 1' }, | ||
{ id: 'id0002', name: 'Name 2' }, | ||
{ id: 'id0003', name: 'Name 3' } | ||
]; | ||
</script> | ||
|
||
<style> | ||
h1 { | ||
color: red; | ||
font-family: Arial, Helvetica, sans-serif; | ||
font-size: 2em; | ||
} | ||
</style> | ||
|
||
<h1>Hello {name}!</h1> | ||
<img {src} alt="Example image"> | ||
|
||
<!-- import external component --> | ||
<Nested/> | ||
|
||
<ul> | ||
{#each names as { id, name }} | ||
<li>{name} ({id})</li> | ||
{/each} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
[ | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"script"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameAttribute","value":"lang"}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"LiteralString","value":"\"typescript\""}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"CommentSingle","value":"// Nested is defined elsewhere\n"}, | ||
{"type":"Text","value":"\t"}, | ||
{"type":"KeywordReserved","value":"import"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"Nested"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"KeywordReserved","value":"from"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'./Nested.svelte'"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\n\t"}, | ||
{"type":"KeywordDeclaration","value":"let"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"src"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'example.png'"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"KeywordDeclaration","value":"let"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'world'"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\n\t"}, | ||
{"type":"KeywordDeclaration","value":"let"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"names"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"["}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"id"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'id0001'"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'Name 1'"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"},"}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"id"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'id0002'"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'Name 2'"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"},"}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"id"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'id0003'"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Operator","value":":"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"LiteralStringSingle","value":"'Name 3'"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"Punctuation","value":"];"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"script"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"style"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"NameTag","value":"h1"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"NameOther","value":"color"}, | ||
{"type":"Text","value":": "}, | ||
{"type":"KeywordType","value":"red"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"NameOther","value":"font"}, | ||
{"type":"Operator","value":"-"}, | ||
{"type":"NameOther","value":"family"}, | ||
{"type":"Text","value":": "}, | ||
{"type":"KeywordType","value":"Arial"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"Helvetica"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"sans"}, | ||
{"type":"Operator","value":"-"}, | ||
{"type":"NameOther","value":"serif"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\t\t"}, | ||
{"type":"NameOther","value":"font"}, | ||
{"type":"Operator","value":"-"}, | ||
{"type":"NameOther","value":"size"}, | ||
{"type":"Text","value":": "}, | ||
{"type":"KeywordType","value":"2em"}, | ||
{"type":"Punctuation","value":";"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"style"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"h1"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"Hello "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":"!"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"h1"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"img"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"NameOther","value":"src"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameAttribute","value":"alt"}, | ||
{"type":"Operator","value":"="}, | ||
{"type":"LiteralString","value":"\"Example image\""}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Comment","value":"\u003c!-- import external component --\u003e"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"Nested"}, | ||
{"type":"Punctuation","value":"/\u003e"}, | ||
{"type":"Text","value":"\n\n"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"ul"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Keyword","value":"#each"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"names"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"KeywordReserved","value":"as"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"id"}, | ||
{"type":"Punctuation","value":","}, | ||
{"type":"Text","value":" "}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Text","value":" "}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":"}\n\t\t"}, | ||
{"type":"Punctuation","value":"\u003c"}, | ||
{"type":"NameTag","value":"li"}, | ||
{"type":"Punctuation","value":"\u003e{"}, | ||
{"type":"NameOther","value":"name"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":" ("}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"NameOther","value":"id"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":")"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"li"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n\t"}, | ||
{"type":"Punctuation","value":"{"}, | ||
{"type":"Keyword","value":"/each"}, | ||
{"type":"Punctuation","value":"}"}, | ||
{"type":"Text","value":"\n"}, | ||
{"type":"Punctuation","value":"\u003c/"}, | ||
{"type":"NameTag","value":"ul"}, | ||
{"type":"Punctuation","value":"\u003e"}, | ||
{"type":"Text","value":"\n"} | ||
] |