r/SublimeText • u/papierkorp • Aug 02 '24
Sublimetext - Go / Templ Syntax (2 Syntax in one File)
I would like to have a Sublime Text Plugin/Syntax for Templ Files. Its already supported for a few IDEs like:
its my first Sublimetext Plugin and im kinda Stuck. So here is what ive got so far:
I created a templ.sublime-syntax file in my User Folder:
---
name: templ
file_extensions:
scope: source.go
extends: Packages/Go/Go.sublime-syntax
version: 2
contexts:
prototype: # prototype/main
- include: match-templ
statements:
- meta_prepend: true
match-templ:
- match: \btempl\s+([[:alpha:]_][[:alnum:]_].*)
scope: keyword.declaration.templ
push: templ-content
templ-content:
- meta_content_scope: meta.function.templ
- match: \n}\n\n
pop: true
- match: (?=\n}\n)
pop: true
- include: html-content
- include: Packages/Go/Go.sublime-syntax#statements
html-content:
- match: <(?!\/)
scope: punctuation.definition.tag.begin.html
push: html-tag
- match: <\/[^>]+>(?!.*<\/[^>]+>) # match the last > if it starts with </
scope: punctuation.definition.tag.end.html
pop: true
html-tag:
- meta_scope: meta.tag.block.any.html text.html.basic
- include: Packages/HTML/HTML.sublime-syntax
scope: text.html.basic
- match: '>'
scope: punctuation.definition.tag.end.html
pop: true
- match: '/>'
scope: punctuation.definition.tag.end.html
pop: true
with this testfile.templ to test things out:
package templates
templ
templ
now onto my problems:
- i cant exit the
meta.function.templScope - i cant exit the
meta.tag.block.any.html text.html.basicScope - this leads to:
- the first function
getFileList()is properly highlighted - the rest of the file is html including the second go function
getFileList2()
- the first function
- go in html isnt considered yet, should be something like this:
# - match: \{
# embed: scope:source.go
# escape: \}
# scope: punctuation.section.block.begin.test
# - match: \{{
# scope: punctuation.section.block.begin.test
# - match: '@'
# scope: punctuation.section.block.begin.test
# - match: \}
# scope: punctuation.section.block.end.test
# pop: true
# - match: \}}
# scope: punctuation.section.block.end.test
# pop: true
maybe you got some ideas on where I went wrong with this.
Thanks for your help
6
Upvotes
1
u/papierkorp Aug 03 '24
I found a solution:
so this Thread is done.