Skip to content

Commit cbc2382

Browse files
GregOnNetbasarat
authored andcommitted
Issue 818/angular component html highlighing (#948)
* Adds custom grammar enabling html syntax highlighting Applies for @component decorator provided by Angular 2 #818 * Applies grammar for html syntax highlighting to ts.cson and tsx.cson This is done by running `npm run build` #818 * Allows backticks inside html-templates without breaking syntax-highlighting * Updates TypeScript grammar based on grammar.js Done by running npm run build
1 parent 99a6302 commit cbc2382

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

grammars/ts.cson

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is generated by `scripts/grammar.js`
2-
# Last generated: Mon, 18 Apr 2016 17:58:05 GMT
2+
# Last generated: Sat, 14 May 2016 07:40:19 GMT
33
name: "TypeScript"
44
scopeName: "source.ts"
55
fileTypes: [
@@ -609,6 +609,22 @@ repository:
609609
expression:
610610
name: "meta.expression.ts"
611611
patterns: [
612+
{
613+
comment: "Match Angular 2 Component html templates"
614+
begin: "(?:(?<=^|\\stemplate:)|(?<=/\\*\\* @html \\*/))\\s*(`)"
615+
beginCaptures:
616+
"1":
617+
name: "name: string.template.ts"
618+
end: "(?<!\\\\)`"
619+
endCaptures:
620+
"0":
621+
name: "name: string.template.ts"
622+
patterns: [
623+
{
624+
include: "text.html.basic"
625+
}
626+
]
627+
}
612628
{
613629
comment: "Match ES6 \"import from\" syntax"
614630
match: "\\b(import)\\b.*\\b(from)\\b\\s+((['\"]).*\\4)"
@@ -868,13 +884,13 @@ repository:
868884
match: "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%"
869885
"relational-operator":
870886
name: "keyword.operator.comparison.ts"
871-
match: "===|==|=|!=|!==|<=|>=|<>|<|>"
887+
match: "===|!==|==|!=|<=|>=|<>|=|<|>"
872888
"assignment-operator":
873889
name: "keyword.operator.assignment.ts"
874-
match: "<<=|>>=|>>>=|\\*=|(?<!\\()/=|%=|\\+=|\\-=|&=|\\^="
890+
match: "<<=|>>>=|>>=|\\*=|(?<!\\()/=|%=|\\+=|\\-=|&=|\\^="
875891
"logic-operator":
876892
name: "keyword.operator.arithmetic.ts"
877-
match: "\\!|&|~|\\^|\\||&&|\\|\\|"
893+
match: "\\!|&&|&|~|\\^|\\|\\||\\|"
878894
"storage-keyword":
879895
name: "storage.type.ts"
880896
match: "\\b(var|let|function|const|module|namespace|void|export)\\b"

grammars/tsx.cson

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is generated by `scripts/grammar.js`
2-
# Last generated: Mon, 18 Apr 2016 17:58:05 GMT
2+
# Last generated: Sat, 14 May 2016 07:40:19 GMT
33
name: "TypeScriptReact"
44
scopeName: "source.tsx"
55
fileTypes: [
@@ -609,6 +609,22 @@ repository:
609609
expression:
610610
name: "meta.expression.tsx"
611611
patterns: [
612+
{
613+
comment: "Match Angular 2 Component html templates"
614+
begin: "(?:(?<=^|\\stemplate:)|(?<=/\\*\\* @html \\*/))\\s*(`)"
615+
beginCaptures:
616+
"1":
617+
name: "name: string.template.ts"
618+
end: "(?<!\\\\)`"
619+
endCaptures:
620+
"0":
621+
name: "name: string.template.ts"
622+
patterns: [
623+
{
624+
include: "text.html.basic"
625+
}
626+
]
627+
}
612628
{
613629
comment: "Match ES6 \"import from\" syntax"
614630
match: "\\b(import)\\b.*\\b(from)\\b\\s+((['\"]).*\\4)"
@@ -853,13 +869,13 @@ repository:
853869
match: "\\*|/|\\-\\-|\\-|\\+\\+|\\+|%"
854870
"relational-operator":
855871
name: "keyword.operator.comparison.tsx"
856-
match: "===|==|=|!=|!==|<=|>=|<>|<|>"
872+
match: "===|!==|==|!=|<=|>=|<>|=|<|>"
857873
"assignment-operator":
858874
name: "keyword.operator.assignment.tsx"
859-
match: "<<=|>>=|>>>=|\\*=|(?<!\\()/=|%=|\\+=|\\-=|&=|\\^="
875+
match: "<<=|>>>=|>>=|\\*=|(?<!\\()/=|%=|\\+=|\\-=|&=|\\^="
860876
"logic-operator":
861877
name: "keyword.operator.arithmetic.tsx"
862-
match: "\\!|&|~|\\^|\\||&&|\\|\\|"
878+
match: "\\!|&&|&|~|\\^|\\|\\||\\|"
863879
"storage-keyword":
864880
name: "storage.type.tsx"
865881
match: "\\b(var|let|function|const|module|namespace|void|export)\\b"

scripts/grammar.js

+12
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ var atomPatterns = [
9494
name: 'es6import.path.string.quoted'
9595
}
9696
}
97+
},
98+
{
99+
comment: 'Match Angular 2 Component html templates',
100+
begin: '(?:(?<=^|\\stemplate:)|(?<=/\\*\\* @html \\*/))\\s*(`)',
101+
beginCaptures: {
102+
'1': { name: 'name: string.template.ts' }
103+
},
104+
end: '(?<!\\\\)`',
105+
endCaptures: {
106+
'0': { name: 'name: string.template.ts' }
107+
},
108+
patterns: [ { include: 'text.html.basic' } ]
97109
}
98110
]
99111

0 commit comments

Comments
 (0)