From 3be90a682a79d46e95cc8935df19f81498f113b0 Mon Sep 17 00:00:00 2001 From: Wei Ting Date: Thu, 10 Mar 2022 01:32:03 +0800 Subject: [PATCH] Use `key`, `value` for token names; `attr-name`, `attr-value` as aliases --- components/prism-properties.js | 10 ++++--- components/prism-properties.min.js | 2 +- .../properties/key_value_feature.test | 26 +++++++++---------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/components/prism-properties.js b/components/prism-properties.js index e9e01ff1bf..a5834fc52b 100644 --- a/components/prism-properties.js +++ b/components/prism-properties.js @@ -1,9 +1,13 @@ Prism.languages.properties = { 'comment': /^[ \t]*[#!].*$/m, - 'attr-value': { + 'value': { pattern: /(^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?: *[=:] *(?! )| ))(?:\\(?:\r\n|[\s\S])|[^\\\r\n])+/m, - lookbehind: true + lookbehind: true, + alias: 'attr-value' + }, + 'key': { + pattern: /^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?= *[=:]| )/m, + alias: 'attr-name' }, - 'attr-name': /^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?= *[=:]| )/m, 'punctuation': /[=:]/ }; diff --git a/components/prism-properties.min.js b/components/prism-properties.min.js index d90930c9c1..5976d47656 100644 --- a/components/prism-properties.min.js +++ b/components/prism-properties.min.js @@ -1 +1 @@ -Prism.languages.properties={comment:/^[ \t]*[#!].*$/m,"attr-value":{pattern:/(^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?: *[=:] *(?! )| ))(?:\\(?:\r\n|[\s\S])|[^\\\r\n])+/m,lookbehind:!0},"attr-name":/^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?= *[=:]| )/m,punctuation:/[=:]/}; \ No newline at end of file +Prism.languages.properties={comment:/^[ \t]*[#!].*$/m,value:{pattern:/(^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?: *[=:] *(?! )| ))(?:\\(?:\r\n|[\s\S])|[^\\\r\n])+/m,lookbehind:!0,alias:"attr-value"},key:{pattern:/^[ \t]*(?:\\(?:\r\n|[\s\S])|[^\\\s:=])+(?= *[=:]| )/m,alias:"attr-name"},punctuation:/[=:]/}; \ No newline at end of file diff --git a/tests/languages/properties/key_value_feature.test b/tests/languages/properties/key_value_feature.test index 0762a53253..70ecb9eb0e 100644 --- a/tests/languages/properties/key_value_feature.test +++ b/tests/languages/properties/key_value_feature.test @@ -11,26 +11,26 @@ baz ---------------------------------------------------- [ - ["attr-name", "foo"], - ["attr-value", "bar"], - ["attr-name", "foo\\:\\=\\ bar"], - ["attr-value", "bar\\:\\= \\\r\nbaz"], + ["key", "foo"], + ["value", "bar"], + ["key", "foo\\:\\=\\ bar"], + ["value", "bar\\:\\= \\\r\nbaz"], - ["attr-name", "foo"], + ["key", "foo"], ["punctuation", "="], - ["attr-value", "bar"], - ["attr-name", "foo\\:\\=\\ bar"], + ["value", "bar"], + ["key", "foo\\:\\=\\ bar"], ["punctuation", "="], - ["attr-value", "bar\\:\\= \\\r\nbaz"], + ["value", "bar\\:\\= \\\r\nbaz"], - ["attr-name", "foo"], + ["key", "foo"], ["punctuation", ":"], - ["attr-value", "bar"], - ["attr-name", "foo\\:\\=\\ bar"], + ["value", "bar"], + ["key", "foo\\:\\=\\ bar"], ["punctuation", ":"], - ["attr-value", "bar\\:\\= \\\r\nbaz"] + ["value", "bar\\:\\= \\\r\nbaz"] ] ---------------------------------------------------- -Checks for keys and values. \ No newline at end of file +Checks for keys and values.