EditorConfig: Trim spaces before key and section title (#2482) The `key` and `section` tokens sometimes included leading spaces.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/components/prism-editorconfig.js b/components/prism-editorconfig.js
index 5cab128..c7c68b0 100644
--- a/components/prism-editorconfig.js
+++ b/components/prism-editorconfig.js
@@ -2,7 +2,8 @@ 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 '\\'
@@ -10,7 +11,10 @@ Prism.languages.editorconfig = {
'punctuation': /[\[\]{},]/
}
},
- 'property': /^[ \t]*[^\s=]+(?=[ \t]*=)/m,
+ 'property': {
+ pattern: /(^[ \t]*)[^\s=]+(?=[ \t]*=)/m,
+ lookbehind: true
+ },
'value': {
pattern: /=.*/,
alias: 'string',
diff --git a/components/prism-editorconfig.min.js b/components/prism-editorconfig.min.js
index 58fdfdf..fd7ddd7 100644
--- a/components/prism-editorconfig.min.js
+++ b/components/prism-editorconfig.min.js
@@ -1 +1 @@
-Prism.languages.editorconfig={comment:/[;#].*/,section:{pattern:/^[ \t]*\[.+]/m,alias:"keyword",inside:{regex:/\\\\[\[\]{},!?.*]/,operator:/[!?]|\.\.|\*{1,2}/,punctuation:/[\[\]{},]/}},property:/^[ \t]*[^\s=]+(?=[ \t]*=)/m,value:{pattern:/=.*/,alias:"string",inside:{punctuation:/^=/}}};
\ No newline at end of file
+Prism.languages.editorconfig={comment:/[;#].*/,section:{pattern:/(^[ \t]*)\[.+]/m,lookbehind:!0,alias:"keyword",inside:{regex:/\\\\[\[\]{},!?.*]/,operator:/[!?]|\.\.|\*{1,2}/,punctuation:/[\[\]{},]/}},property:{pattern:/(^[ \t]*)[^\s=]+(?=[ \t]*=)/m,lookbehind:!0},value:{pattern:/=.*/,alias:"string",inside:{punctuation:/^=/}}};
\ No newline at end of file
diff --git a/tests/languages/editorconfig/key_value_feature.test b/tests/languages/editorconfig/key_value_feature.test
index 881f6a1..dfcbd6a 100644
--- a/tests/languages/editorconfig/key_value_feature.test
+++ b/tests/languages/editorconfig/key_value_feature.test
@@ -1,5 +1,6 @@
foo = Bar Baz
foobar = 42
+ another_value = with_indent
----------------------------------------------------
@@ -13,6 +14,11 @@ foobar = 42
["value", [
["punctuation", "="],
" 42"
+ ]],
+ ["property", "another_value"],
+ ["value", [
+ ["punctuation", "="],
+ " with_indent"
]]
]
diff --git a/tests/languages/editorconfig/section_feature.test b/tests/languages/editorconfig/section_feature.test
index 9ba7b59..ae24c74 100644
--- a/tests/languages/editorconfig/section_feature.test
+++ b/tests/languages/editorconfig/section_feature.test
@@ -3,6 +3,7 @@
[{**.kt, **.kts}]
[?[!seq].log.{0..9}]
[\\**.log]
+ [Section with indent]
----------------------------------------------------
@@ -26,6 +27,9 @@
]],
["section", [
["punctuation", "["], ["regex", "\\\\*"], ["operator", "*"], ".log", ["punctuation", "]"]
+ ]],
+ ["section", [
+ ["punctuation", "["], "Section with indent", ["punctuation", "]"]
]]
]