8000 Added support for HCL (#1594) · PrismJS/prism@c939df8 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c939df8

Browse files
outsiderisRunDevelopment
authored andcommitted
Added support for HCL (#1594)
Adds support for HCL ([HashiCorp configuration language](https://github.com/hashicorp/hcl)).
1 parent 4f6f3c7 commit c939df8

13 files changed

+459
-3
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@
337337
"require": "clike",
338338
"owner": "Golmote"
339339
},
340+
"hcl": {
341+
"title": "HCL",
342+
"owner": "outsideris"
343+
},
340344
"http": {
341345
"title": "HTTP",
342346
"peerDependencies": [

components/prism-hcl.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Prism.languages.hcl = {
2+
'comment': /(?:\/\/|#).*|\/\*[\s\S]*?(?:\*\/|$)/,
3+
'heredoc': {
4+
pattern: /<<-?(\w+)[\s\S]*?^\s*\1/m,
5+
greedy: true,
6+
alias: 'string'
7+
},
8+
'keyword': [
9+
{
10+
pattern: /(?:resource|data)\s+(?:"(?:\\[\s\S]|[^\\"])*")(?=\s+"[\w-]+"\s+{)/i,
11+
inside: {
12+
'type': {
13+
pattern: /(resource|data|\s+)(?:"(?:\\[\s\S]|[^\\"])*")/i,
14+
lookbehind: true,
15+
alias: 'variable'
16+
}
17+
}
18+
},
19+
{
20+
pattern: /(?:provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+(?={)/i,
21+
inside: {
22+
'type': {
23+
pattern: /(provider|provisioner|variable|output|module|backend)\s+(?:[\w-]+|"(?:\\[\s\S]|[^\\"])*")\s+/i,
24+
lookbehind: true,
25+
alias: 'variable'
26+
}
27+
}
28+
},
29+
{
30+
pattern: /[\w-]+(?=\s+{)/
31+
}
32+
],
33+
'property': [
34+
/[\w-\.]+(?=\s*=(?!=))/,
35+
/"(?:\\[\s\S]|[^\\"])+"(?=\s*[:=])/,
36+
],
37+
'string': {
38+
pattern: /"(?:[^\\$"]|\\[\s\S]|\$(?:(?=")|\$+|[^"${])|\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\})*"/,
39+
greedy: true,
40+
inside: {
41+
'interpolation': {
42+
pattern: /(^|[^$])\$\{(?:[^{}"]|"(?:[^\\"]|\\[\s\S])*")*\}/,
43+
lookbehind: true,
44+
inside: {
45+
'type': {
46+
pattern: /(\b(?:terraform|var|self|count|module|path|data|local)\b\.)[\w\*]+/i,
47+
lookbehind: true,
48+
alias: 'variable'
49+
},
50+
'keyword': /\b(?:terraform|var|self|count|module|path|data|local)\b/i,
51+
'function': /\w+(?=\()/,
52+
'string': {
53+
pattern: /"(?:\\[\s\S]|[^\\"])*"/,
54+
greedy: true,
55+
},
56+
'number': /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,
57+
'punctuation': /[!\$#%&'()*+,.\/;<=>@\[\\\]^`{|}~?:]/,
58+
}
59+
},
60+
}
61+
},
62+
'number': /\b0x[\da-f]+|\d+\.?\d*(?:e[+-]?\d+)?/i,
63+
'boolean': /\b(?:true|false)\b/i,
64+
'punctuation': /[=\[\]{}]/,
65+
};

components/prism-hcl.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-hcl.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h2>Comments</h2>
2+
<pre><code># Configure the AWS Provider
3+
// Configure the AWS Provider
4+
</code></pre>
5+
6+
<h2>Resources</h2>
7+
<pre><code>resource "aws_instance" "web" {
8+
ami = "${data.aws_ami.ubuntu.id}"
9+
instance_type = "t2.micro"
10+
11+
tags {
12+
Name = "HelloWorld"
13+
}
14+
}</code></pre>
15+
16+
<h2>Provider</h2>
17+
<pre><code>provider "aws" {
18+
access_key = "${var.aws_access_key}"
19+
secret_key = "${var.aws_secret_key}"
20+
region = "us-east-1"
21+
}</code></pre>
22+
23+
<h2>Variables</h2>
24+
<pre><code>variable "images" {
25+
type = "map"
26+
27+
default = {
28+
us-east-1 = "image-1234"
29+
us-west-2 = "image-4567"
30+
}
31+
}</code></pre>
32+
33+
<h2>Outputs</h2>
34+
<pre><code>output "address" {
35+
value = "${aws_instance.db.public_dns}"
36+
}</code></pre>
37+
38+
<h2>Modules</h2>
39+
<pre><code>module "consul" {
40+
source = "hashicorp/consul/aws"
41+
servers = 5
42+
}</code></pre>

plugins/show-language/prism-show-language.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# foo bar
2+
// foo bar
3+
/*
4+
* multi line
5+
*/
6+
7+
----------------------------------------------------
8+
9+
[
10+
["comment", "# foo bar"],
11+
["comment", "// foo bar"],
12+
["comment", "/*\r\n * multi line\r\n */"]
13+
]
14+
15+
----------------------------------------------------
16+
17+
Checks for comments.
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
"${data.aws_availability_zones.available.names[0]}"
2+
"${aws_db_subnet_group.default.id}"
3+
"${var.something ? 1 : 0}"
4+
"${var.num ? 1.02 : 0}"
5+
"${length(var.hostnames)}"
6+
"${format("web-%03d", count.index + 1)}"
7+
"${file("templates/web_init.tpl")}"
8+
"${replace(var.sub_domain, ".", "\\\\\\\\.")}"
9+
"${filepath.foo}"
10+
11+
----------------------------------------------------
12+
13+
[
14+
["string",
15+
[
16+
"\"",
17+
[
18+
"interpolation",
19+
[
20+
["punctuation", "$"],
21+
["punctuation", "{"],
22+
["keyword", "data"],
23+
["punctuation", "."],
24+
["type", "aws_availability_zones"],
25+
["punctuation", "."],
26+
"available",
27+
["punctuation", "."],
28+
"names",
29+
["punctuation", "["],
30+
["number", "0"],
31+
["punctuation", "]"],
32+
["punctuation", "}"]
33+
]
34+
],
35+
"\""
36+
]
37+
],
38+
["string",
39+
[
40+
"\"",
41+
[
42+
"interpolation",
43+
[
44+
["punctuation", "$"],
45+
["punctuation", "{"],
46+
"aws_db_subnet_group",
47+
["punctuation", "."],
48+
"default",
49+
["punctuation", "."],
50+
"id",
51+
["punctuation", "}"]
52+
]
53+
],
54+
"\""
55+
]
56+
],
57+
["string",
58+
[
59+
"\"",
60+
[
61+
"interpolation",
62+
[
63+
["punctuation", "$"],
64+
["punctuation", "{"],
65+
["keyword", "var"],
66+
["punctuation", "."],
67+
["type", "something"],
68+
["punctuation", "?"],
69+
["number", "1"],
70+
["punctuation", ":"],
71+
["number", "0"],
72+
["punctuation", "}"]
73+
]
74+
],
75+
"\""
76+
]
77+
],
78+
["string",
79+
[
80+
"\"",
81+
[
82+
"interpolation",
83+
[
84+
["punctuation", "$"],
85+
["punctuation", "{"],
86+
["keyword", "var"],
87+
["punctuation", "."],
88+
["type", "num"],
89+
["punctuation", "?"],
90+
["number", "1.02"],
91+
["punctuation", ":"],
92+
["number", "0"],
93+
["punctuation", "}"]
94+
]
95+
],
96+
"\""
97+
]
98+
],
99+
["string",
100+
[
101+
"\"",
102+
[
103+
"interpolation",
104+
[
105+
["punctuation", "$"],
106+
["punctuation", "{"],
107+
["function", "length"],
108+
["punctuation", "("],
109+
["keyword", "var"],
110+
["punctuation", "."],
111+
["type", "hostnames"],
112+
["punctuation", ")"],
113+
["punctuation", "}"]
114+
]
115+
],
116+
"\""
117+
]
118+
],
119+
["string",
120+
[
121+
"\"",
122+
[
123+
"interpolation",
124+
[
125+
["punctuation", "$"],
126+
["punctuation", "{"],
127+
["function", "format"],
128+
["punctuation", "("],
129+
["string", "\"web-%03d\""],
130+
["punctuation", ","],
131+
["keyword", "count"],
132+
["punctuation", "."],
133+
["type", "index"],
134+
["punctuation", "+"],
135+
["number", "1"],
136+
["punctuation", ")"],
137+
["punctuation", "}"]
138+
]
139+
],
140+
"\""
141+
]
142+
],
143+
["string",
144+
[
145+
"\"",
146+
[
147+
"interpolation",
148+
[
149+
["punctuation", "$"],
150+
["punctuation", "{"],
151+
["function", "file"],
152+
["punctuation", "("],
153+
["string", "\"templates/web_init.tpl\""],
154+
["punctuation", ")"],
155+
["punctuation", "}"]
156+
]
157+
],
158+
"\""
159+
]
160+
],
161+
["string",
162+
[
163+
"\"",
164+
[
165+
"interpolation",
166+
[
167+
["punctuation", "$"],
168+
["punctuation", "{"],
169+
["function", "replace"],
170+
["punctuation", "("],
171+
["keyword", "var"],
172+
["punctuation", "."],
173+
["type", "sub_domain"],
174+
["punctuation", ","],
175+
["string", "\".\""],
176+
["punctuation", ","],
177+
["string", "\"\\\\\\\\\\\\\\\\.\""],
178+
["punctuation", ")"],
179+
["punctuation", "}"]
180+
]
181+
],
182+
"\""
183+
]
184+
],
185+
["string",
186+
[
187+
"\"",
188+
[
189+
"interpolation",
190+
[
191+
["punctuation", "$"],
192+
["punctuation", "{"],
193+
"filepath",
194+
["punctuation", "."],
195+
"foo",
196+
["punctuation", "}"]
197+
]
198+
],
199+
"\""
200+
]
201+
]
202+
]
203+
204+
----------------------------------------------------
205+
206+
Checks for all interpolation.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
resource "aws_db_instance" "main" {
2+
data "terraform_remote_state" "main" {
3+
output "dev_vpc_id" {
4+
config {
5+
terraform {
6+
7+
----------------------------------------------------
8+
9+
[
10+
["keyword",
11+
["resource ",
12+
["type", "\"aws_db_instance\""]]],
13+
["string", ["\"main\""]],
14+
["punctuation", "{"],
15+
["keyword",
16+
["data ",
17+
["type", "\"terraform_remote_state\""]]],
18+
["string", ["\"main\""]],
19+
["punctuation", "{"],
20+
["keyword",
21+
["output",
22+
["type", " \"dev_vpc_id\" "]]],
23+
["punctuation", "{"],
24+
["keyword", "config"],
25+
["punctuation", "{"],
26+
["keyword", "terraform"],
27+
["punctuation", "{"]
28+
]
29+
30+
----------------------------------------------------
31+
32+
Checks for all keywords.

0 commit comments

Comments
 (0)
0