Skip to content

Commit 0a07822

Browse files
osipxdquentinvernot
authored andcommitted
Added support for EditorConfig (PrismJS#2471)
1 parent f73499e commit 0a07822

10 files changed

+146
-2
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@
295295
"title": "EBNF",
296296
"owner": "RunDevelopment"
297297
},
298+
"editorconfig": {
299+
"title": "EditorConfig",
300+
"owner": "osipxd"
301+
},
298302
"eiffel": {
299303
"title": "Eiffel",
300304
"owner": "Conaclos"

components/prism-editorconfig.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Prism.languages.editorconfig = {
2+
// https://editorconfig-specification.readthedocs.io/en/latest/
3+
'comment': /[;#].*/,
4+
'section': {
5+
pattern: /^[ \t]*\[.+]/m,
6+
alias: 'keyword',
7+
inside: {
8+
'regex': /\\\\[\[\]{},!?.*]/, // Escape special characters with '\\'
9+
'operator': /[!?]|\.\.|\*{1,2}/,
10+
'punctuation': /[\[\]{},]/
11+
}
12+
},
13+
'property': /^[ \t]*[^\s=]+(?=[ \t]*=)/m,
14+
'value': {
15+
pattern: /=.*/,
16+
alias: 'string',
17+
inside: {
18+
'punctuation': /^=/
19+
}
20+
}
21+
};

components/prism-editorconfig.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-editorconfig.html

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<h2>Comment</h2>
2+
<pre><code># This is a comment
3+
; And this is too</code></pre>
4+
5+
<h2>Section Header</h2>
6+
<pre><code>[*]
7+
[*.js]
8+
[*.{bash,sh,zsh}]</code></pre>
9+
10+
<h2>Key-Value Pair</h2>
11+
<pre><code>key = value
12+
indent_style = space</code></pre>
13+
14+
<h2>Full example</h2>
15+
<pre><code># EditorConfig is awesome: https://EditorConfig.org
16+
17+
# top-most EditorConfig file
18+
root = true
19+
20+
# Unix-style newlines with a newline ending every file
21+
[*]
22+
end_of_line = lf
23+
insert_final_newline = true
24+
25+
# Matches multiple files with brace expansion notation
26+
# Set default charset
27+
[*.{js,py}]
28+
charset = utf-8
29+
30+
# 4 space indentation
31+
[*.py]
32+
indent_style = space
33+
indent_size = 4
34+
35+
# Tab indentation (no size specified)
36+
[Makefile]
37+
indent_style = tab
38+
39+
# Indentation override for all JS under lib directory
40+
[lib/**.js]
41+
indent_style = space
42+
indent_size = 2
43+
44+
# Matches the exact files either package.json or .travis.yml
45+
[{package.json,.travis.yml}]
46+
indent_style = space
47+
indent_size = 2</code></pre>

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

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"dns-zone": "DNS zone file",
5858
"dockerfile": "Docker",
5959
"ebnf": "EBNF",
60+
"editorconfig": "EditorConfig",
6061
"ejs": "EJS",
6162
"etlua": "Embedded Lua templating",
6263
"erb": "ERB",

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

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;
2+
; comment
3+
# comment can also contain ; and #
4+
5+
----------------------------------------------------
6+
7+
[
8+
["comment", ";"],
9+
["comment", "; comment"],
10+
["comment", "# comment can also contain ; and #"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
foo = Bar Baz
2+
foobar = 42
3+
4+
----------------------------------------------------
5+
6+
[
7+
["property", "foo"],
8+
["value", [
9+
["punctuation", "="],
10+
" Bar Baz"
11+
]],
12+
["property", "foobar"],
13+
["value", [
14+
["punctuation", "="],
15+
" 42"
16+
]]
17+
]
18+
19+
----------------------------------------------------
20+
21+
Checks for key/value pairs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[*]
2+
[**.kt]
3+
[{**.kt, **.kts}]
4+
[?[!seq].log.{0..9}]
5+
[\\**.log]
6+
7+
----------------------------------------------------
8+
9+
[
10+
["section", [
11+
["punctuation", "["], ["operator", "*"], ["punctuation", "]"]
12+
]],
13+
["section", [
14+
["punctuation", "["], ["operator", "**"], ".kt", ["punctuation", "]"]
15+
]],
16+
["section", [
17+
["punctuation", "["], ["punctuation", "{"],
18+
["operator", "**"], ".kt", ["punctuation", ","], ["operator", "**"], ".kts",
19+
["punctuation", "}"], ["punctuation", "]"]
20+
]],
21+
["section", [
22+
["punctuation", "["], ["operator", "?"],
23+
["punctuation", "["], ["operator", "!"], "seq", ["punctuation", "]"],
24+
".log.", ["punctuation", "{"], "0", ["operator", ".."], "9", ["punctuation", "}"],
25+
["punctuation", "]"]
26+
]],
27+
["section", [
28+
["punctuation", "["], ["regex", "\\\\*"], ["operator", "*"], ".log", ["punctuation", "]"]
29+
]]
30+
]
31+
32+
----------------------------------------------------
33+
34+
Checks for section titles.

0 commit comments

Comments
 (0)