Commit 0c30c5823dc46a2dd85b6627d9591b7a127ee4da

Osip Fatkullin 2020-07-22T17:45:05

EditorConfig: Trim spaces before key and section title (#2482) The `key` and `section` tokens sometimes included leading spaces.

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", "]"]
     ]]
 ]