Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Register embedded languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Jul 19, 2021
1 parent 205710a commit 6071d4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Next
- Added embedded language registration to allow full support for JavaScript and CSS inside Astro-HTML.
- Changed grammar scope name from `source.astro` to `text.html.astro`.
- Refactored syntax highlighter.

Expand Down
20 changes: 16 additions & 4 deletions grammars/astro.tmLanguage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ repository:
patterns:
- name: meta.block.html
begin: '(?<!\A)\s*^---$'
end: '(?<=</html>)\s*$\Z'
end: '.\Z'
patterns:
- include: '#astro'
- include: 'text.html.basic'

astro:
patterns:
- include: '#inline-javascript'
- include: '#embedded'
- include: '#components'

repository:
Expand All @@ -39,13 +40,26 @@ repository:
patterns:
- include: 'source.js'

embedded:
patterns:
- name: meta.block.embedded.js
begin: '<script>'
end: '</script>'
patterns:
- include: 'source.js'
- name: meta.block.embedded.css
begin: '<style>'
end: '</style>'
patterns:
- include: 'source.css'

components:
patterns:
- name: meta.component.astro
begin: '</?(?=[A-Z])'
end: '/?>'
captures:
0: { name: punctuation.definition.tag.component.astro }
'0': { name: punctuation.definition.tag.component.astro }
patterns:
- include: '#component-name'
- include: '#attribute-name'
Expand All @@ -62,7 +76,5 @@ repository:
- name: string.quoted.attribute-value.astro
begin: '(?<==)"'
end: '(?<!\\)"'
patterns:
- name: string.unquoted.attribute-value.astro
match: '(?<==)\S+'
patterns:
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
{
"language": "astro",
"scopeName": "text.html.astro",
"path": "./grammars/astro.tmLanguage.json"
"path": "./grammars/astro.tmLanguage.json",
"embeddedLanguages": {
"text.html.basic": "html",
"source.js": "javascript",
"source.css": "css"
}
}
],
"snippets": [
Expand Down

0 comments on commit 6071d4f

Please sign in to comment.