Skip to content

Commit 7a0e861

Browse files
authored
feat: add syntax highlighting for embedded HTML in TypeScript (#461)
* feat: add syntax highlighting for embedded HTML in TypeScript Injects an HTML TextMate grammar in Angular component `template` decorator properties, in TypeScript files. The grammar is enabled in decorators with a `template` property whose key value is a string surrounded by any number of parantheses or whitespace. This project owes a great deal to https://github.com/natewallace/angular2-inline, who first enabled Angular inline syntax highlighting. * fixup! feat: add syntax highlighting for embedded HTML in TypeScript * fixup! feat: add syntax highlighting for embedded HTML in TypeScript * fixup! feat: add syntax highlighting for embedded HTML in TypeScript
1 parent fa900a4 commit 7a0e861

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

package.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@
4747
"description": "Enables logging of the Angular server to a file. This log can be used to diagnose Angular Server issues. The log may contain file paths, source code, and other potentially sensitive information from your project."
4848
}
4949
}
50-
}
50+
},
51+
"grammars": [
52+
{
53+
"path": "./syntaxes/template.ng.json",
54+
"scopeName": "template.ng",
55+
"injectTo": [
56+
"source.ts"
57+
],
58+
"embeddedLanguages": {
59+
"source.html": "html"
60+
}
61+
}
62+
]
5163
},
5264
"activationEvents": [
5365
"onLanguage:html",

scripts/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ cp package.json yarn.lock angular.png CHANGELOG.md README.md dist
1717
cp client/package.json client/yarn.lock dist/client
1818
# Copy files to server directory
1919
cp server/package.json server/yarn.lock server/README.md dist/server
20+
# Copy files to syntaxes directory
21+
cp -R syntaxes dist/syntaxes
2022

2123
pushd dist
2224
yarn install --production --ignore-scripts

syntaxes/template.ng.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"scopeName": "template.ng",
3+
"injectionSelector": "L:meta.decorator.ts",
4+
"patterns": [
5+
{
6+
"include": "#ts-decorator"
7+
}
8+
],
9+
"repository": {
10+
"ts-decorator": {
11+
"begin": "(template)\\s*(:)",
12+
"beginCaptures": {
13+
"1": {
14+
"name": "meta.object-literal.key.ts"
15+
},
16+
"2": {
17+
"name": "meta.object-literal.key.ts punctuation.separator.key-value.ts"
18+
}
19+
},
20+
"end": "(?=,|})",
21+
"patterns": [
22+
{
23+
"include": "#ts-paren-expression"
24+
},
25+
{
26+
"include": "#ng-template"
27+
}
28+
]
29+
},
30+
31+
"ts-paren-expression": {
32+
"begin": "\\G\\s*(\\()",
33+
"beginCaptures": {
34+
"1": {
35+
"name": "meta.brace.round.ts"
36+
}
37+
},
38+
"end": "\\)",
39+
"endCaptures": {
40+
"0": {
41+
"name": "meta.brace.round.ts"
42+
}
43+
},
44+
"patterns": [
45+
{
46+
"include": "#ts-paren-expression"
47+
},
48+
{
49+
"include": "#ng-template"
50+
}
51+
]
52+
},
53+
54+
"ng-template": {
55+
"begin": "\\G\\s*([`|'|\"])",
56+
"beginCaptures": {
57+
"1": {
58+
"name": "string"
59+
}
60+
},
61+
"end": "\\1",
62+
"endCaptures": {
63+
"0": {
64+
"name": "string"
65+
}
66+
},
67+
"patterns": [
68+
{
69+
"include": "text.html.basic"
70+
}
71+
]
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)