Skip to content

Commit

Permalink
Added support for EditorConfig (PrismJS#2471)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd authored and quentinvernot committed Sep 11, 2020
1 parent f73499e commit 0a07822
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -295,6 +295,10 @@
"title": "EBNF",
"owner": "RunDevelopment"
},
"editorconfig": {
"title": "EditorConfig",
"owner": "osipxd"
},
"eiffel": {
"title": "Eiffel",
"owner": "Conaclos"
Expand Down
21 changes: 21 additions & 0 deletions components/prism-editorconfig.js
@@ -0,0 +1,21 @@
Prism.languages.editorconfig = {
// https://editorconfig-specification.readthedocs.io/en/latest/
'comment': /[;#].*/,
'section': {
pattern: /^[ \t]*\[.+]/m,
alias: 'keyword',
inside: {
'regex': /\\\\[\[\]{},!?.*]/, // Escape special characters with '\\'
'operator': /[!?]|\.\.|\*{1,2}/,
'punctuation': /[\[\]{},]/
}
},
'property': /^[ \t]*[^\s=]+(?=[ \t]*=)/m,
'value': {
pattern: /=.*/,
alias: 'string',
inside: {
'punctuation': /^=/
}
}
};
1 change: 1 addition & 0 deletions components/prism-editorconfig.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions examples/prism-editorconfig.html
@@ -0,0 +1,47 @@
<h2>Comment</h2>
<pre><code># This is a comment
; And this is too</code></pre>

<h2>Section Header</h2>
<pre><code>[*]
[*.js]
[*.{bash,sh,zsh}]</code></pre>

<h2>Key-Value Pair</h2>
<pre><code>key = value
indent_style = space</code></pre>

<h2>Full example</h2>
<pre><code># EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -57,6 +57,7 @@
"dns-zone": "DNS zone file",
"dockerfile": "Docker",
"ebnf": "EBNF",
"editorconfig": "EditorConfig",
"ejs": "EJS",
"etlua": "Embedded Lua templating",
"erb": "ERB",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions tests/languages/editorconfig/comment_feature.test
@@ -0,0 +1,15 @@
;
; comment
# comment can also contain ; and #

----------------------------------------------------

[
["comment", ";"],
["comment", "; comment"],
["comment", "# comment can also contain ; and #"]
]

----------------------------------------------------

Checks for comments.
21 changes: 21 additions & 0 deletions tests/languages/editorconfig/key_value_feature.test
@@ -0,0 +1,21 @@
foo = Bar Baz
foobar = 42

----------------------------------------------------

[
["property", "foo"],
["value", [
["punctuation", "="],
" Bar Baz"
]],
["property", "foobar"],
["value", [
["punctuation", "="],
" 42"
]]
]

----------------------------------------------------

Checks for key/value pairs.
34 changes: 34 additions & 0 deletions tests/languages/editorconfig/section_feature.test
@@ -0,0 +1,34 @@
[*]
[**.kt]
[{**.kt, **.kts}]
[?[!seq].log.{0..9}]
[\\**.log]

----------------------------------------------------

[
["section", [
["punctuation", "["], ["operator", "*"], ["punctuation", "]"]
]],
["section", [
["punctuation", "["], ["operator", "**"], ".kt", ["punctuation", "]"]
]],
["section", [
["punctuation", "["], ["punctuation", "{"],
["operator", "**"], ".kt", ["punctuation", ","], ["operator", "**"], ".kts",
["punctuation", "}"], ["punctuation", "]"]
]],
["section", [
["punctuation", "["], ["operator", "?"],
["punctuation", "["], ["operator", "!"], "seq", ["punctuation", "]"],
".log.", ["punctuation", "{"], "0", ["operator", ".."], "9", ["punctuation", "}"],
["punctuation", "]"]
]],
["section", [
["punctuation", "["], ["regex", "\\\\*"], ["operator", "*"], ".log", ["punctuation", "]"]
]]
]

----------------------------------------------------

Checks for section titles.

0 comments on commit 0a07822

Please sign in to comment.