Skip to content

Commit

Permalink
EditorConfig: Trim spaces before key and section title (#2482)
Browse files Browse the repository at this point in the history
The `key` and `section` tokens sometimes included leading spaces.
  • Loading branch information
osipxd committed Jul 22, 2020
1 parent 2ff40fe commit 0c30c58
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions components/prism-editorconfig.js
Expand Up @@ -2,15 +2,19 @@ Prism.languages.editorconfig = {
// https://editorconfig-specification.readthedocs.io/en/latest/
'comment': /[;#].*/,
'section': {
pattern: /^[ \t]*\[.+]/m,
pattern: /(^[ \t]*)\[.+]/m,
lookbehind: true,
alias: 'keyword',
inside: {
'regex': /\\\\[\[\]{},!?.*]/, // Escape special characters with '\\'
'operator': /[!?]|\.\.|\*{1,2}/,
'punctuation': /[\[\]{},]/
}
},
'property': /^[ \t]*[^\s=]+(?=[ \t]*=)/m,
'property': {
pattern: /(^[ \t]*)[^\s=]+(?=[ \t]*=)/m,
lookbehind: true
},
'value': {
pattern: /=.*/,
alias: 'string',
Expand Down
2 changes: 1 addition & 1 deletion components/prism-editorconfig.min.js

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

6 changes: 6 additions & 0 deletions tests/languages/editorconfig/key_value_feature.test
@@ -1,5 +1,6 @@
foo = Bar Baz
foobar = 42
another_value = with_indent

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

Expand All @@ -13,6 +14,11 @@ foobar = 42
["value", [
["punctuation", "="],
" 42"
]],
["property", "another_value"],
["value", [
["punctuation", "="],
" with_indent"
]]
]

Expand Down
4 changes: 4 additions & 0 deletions tests/languages/editorconfig/section_feature.test
Expand Up @@ -3,6 +3,7 @@
[{**.kt, **.kts}]
[?[!seq].log.{0..9}]
[\\**.log]
[Section with indent]

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

Expand All @@ -26,6 +27,9 @@
]],
["section", [
["punctuation", "["], ["regex", "\\\\*"], ["operator", "*"], ".log", ["punctuation", "]"]
]],
["section", [
["punctuation", "["], "Section with indent", ["punctuation", "]"]
]]
]

Expand Down

0 comments on commit 0c30c58

Please sign in to comment.