Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.

Commit eb78116

Browse files
committed
feat: add ts/js support
1 parent 22e1b74 commit eb78116

File tree

6 files changed

+206
-2
lines changed

6 files changed

+206
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Adds syntax highlight support for code, placed in es6 multiline strings:
1010
- SVG
1111
- CSS
1212
- GLSL
13+
- JavaScript/TypeScript
1314

1415
## Community
1516
- [python-string-sql](https://github.com/ptweir/python-string-sql) - Highlight SQL code in python multiline strings
@@ -50,12 +51,14 @@ Simply insert the comment /\*html\*/ or `html` (also works with SQL, SVG, XML, j
5051
## Requirements
5152

5253
- Visual Studio Code v1.19.0 and higher
53-
- Comment `/*html*/` before the string. (also works with CSS, SQL, SVG, XML, just use the appropriate word) Possible values:
54+
- Comment `/*html*/` before the string. (also works with CSS, SQL, SVG, XML, JavaScript, just use the appropriate word) Possible values:
5455
- - `/*css*/`
5556
- - `/*html*/`
5657
- - `/*inline-html*/`
5758
- - `/*template*/`
5859
- - `/*inline-template*/`
60+
- - `/*javascript*/` or `/*js*/`
61+
- - `/*typescript*/` or `/*ts*/`
5962
- Or
6063
- - `html` before the string
6164

package.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,26 @@
157157
"embeddedLanguages": {
158158
"meta.embedded.block.sql": "sql"
159159
}
160-
}
160+
},
161+
{
162+
"injectTo": [
163+
"source.html",
164+
"source.js",
165+
"source.js.jsx",
166+
"source.jsx",
167+
"source.ts",
168+
"source.tsx",
169+
"source.vue",
170+
"source.svelte",
171+
"source.sql",
172+
"text.html"
173+
],
174+
"scopeName": "inline.es6-javascript",
175+
"path": "./syntaxes/es6-inline-javascript.json",
176+
"embeddedLanguages": {
177+
"meta.embedded.block.javascript": "javascript"
178+
}
179+
}
161180
]
162181
},
163182
"__metadata": {
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"fileTypes": [
3+
"js",
4+
"jsx",
5+
"ts",
6+
"tsx",
7+
"html",
8+
"vue",
9+
"svelte",
10+
"php"
11+
],
12+
"injectionSelector": "L:source.js -comment -string, L:source.js -comment -string, L:source.jsx -comment -string, L:source.js.jsx -comment -string, L:source.ts -comment -string, L:source.tsx -comment -string",
13+
"injections": {
14+
"L:source": {
15+
"patterns": [
16+
{
17+
"match": "<",
18+
"name": "invalid.illegal.bad-angle-bracket.html"
19+
}
20+
]
21+
}
22+
},
23+
"patterns": [
24+
{
25+
"begin": "(?i)(\\s?\\/\\*\\s?(javascript|inline-javascript|typescript|inline-typescript|js|inline-js|ts|inline-ts)\\s?\\*\\/\\s?)(`)",
26+
"beginCaptures": {
27+
"1": {
28+
"name": "comment.block"
29+
}
30+
},
31+
"end": "(`)",
32+
"patterns": [
33+
{
34+
"include": "source.ts#template-substitution-element"
35+
},
36+
{
37+
"include": "source.js"
38+
},
39+
{
40+
"include": "inline.es6-htmlx#template"
41+
}
42+
]
43+
},
44+
{
45+
"begin": "(?i)(\\s*(javascript|inline-javascript|typescript|inline-typescript|js|inline-js|ts|inline-ts))(`)",
46+
"beginCaptures": {
47+
"1": {
48+
"name": "comment.block"
49+
}
50+
},
51+
"end": "(`)",
52+
"patterns": [
53+
{
54+
"include": "source.ts#template-substitution-element"
55+
},
56+
{
57+
"include": "source.js"
58+
},
59+
{
60+
"include": "inline.es6-htmlx#template"
61+
},
62+
{
63+
"include": "string.quoted.other.template.js"
64+
}
65+
]
66+
},
67+
{
68+
"begin": "(?i)(?<=\\s|\\,|\\=|\\:|\\(|\\$\\()\\s{0,}(((\\/\\*)|(\\/\\/))\\s?(javascript|inline-javascript|typescript|inline-typescript|js|inline-js|ts|inline-ts)[ ]{0,1000}\\*?\\/?)[ ]{0,1000}$",
69+
"beginCaptures": {
70+
"1": {
71+
"name": "comment.line"
72+
}
73+
},
74+
"end": "(`).*",
75+
"patterns": [
76+
{
77+
"begin": "(\\G)",
78+
"end": "(`)"
79+
},
80+
{
81+
"include": "source.ts#template-substitution-element"
82+
},
83+
{
84+
"include": "source.js"
85+
}
86+
]
87+
},
88+
{
89+
"begin": "(\\${)",
90+
"end": "(})",
91+
"beginCaptures": {
92+
"1": {
93+
"name": "entity.name.tag"
94+
}
95+
},
96+
"endCaptures": {
97+
"1": {
98+
"name": "entity.name.tag"
99+
}
100+
},
101+
"patterns": [
102+
{
103+
"include": "source.ts#template-substitution-element"
104+
},
105+
{
106+
"include": "source.js"
107+
}
108+
]
109+
}
110+
],
111+
"scopeName": "inline.es6-javascript"
112+
}

tests/test.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@
8080
</url>
8181
</urlset>
8282
`
83+
84+
variable = /*javascript*/
85+
`
86+
function hello(){
87+
console.log("Hello World!")
88+
}
89+
`
90+
91+
variable = /*js*/
92+
`
93+
function hello(){
94+
console.log("Hello World!")
95+
}
96+
`
97+
98+
variable = /*typescript*/`
99+
function hello(name: string){
100+
console.log("Hello " + name + "!")
101+
}`
102+
103+
variable = /*ts*/`
104+
function hello(name: string){
105+
console.log("Hello " + name + "!")
106+
}`
83107
</script>
84108
</body>
85109
</html>

tests/test.svelte

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@
2929
<loc>http://www.example.com/</loc>
3030
</url>
3131
</urlset>
32+
`,
33+
/*js*/
34+
`
35+
function hello(){
36+
console.log("Hello World!")
37+
}
38+
`,
39+
/*javascript*/
40+
`
41+
function hello(){
42+
console.log("Hello World!")
43+
}
44+
`,
45+
/*ts*/
46+
`
47+
function hello(name: string){
48+
console.log("Hello " + name + "!")
49+
}`,
50+
/*typescript*/
3251
`
52+
function hello(name: string){
53+
console.log("Hello " + name + "!")
54+
}`
3355
]
3456
</script>

tests/test.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,30 @@ export default {
4747
</url>
4848
</urlset>
4949
`
50+
51+
variable = /*javascript*/
52+
`
53+
function hello(){
54+
console.log("Hello World!")
55+
}
56+
`
57+
58+
variable = /*js*/
59+
`
60+
function hello(){
61+
console.log("Hello World!")
62+
}
63+
`
64+
65+
variable = /*typescript*/`
66+
function hello(name: string){
67+
console.log("Hello " + name + "!")
68+
}`
69+
70+
variable = /*ts*/`
71+
function hello(name: string){
72+
console.log("Hello " + name + "!")
73+
}`
5074
},
5175
test: 'asdas'
5276
}

0 commit comments

Comments
 (0)