From 7315fb1c8944a74d58b8359d996009fb963dfa9a Mon Sep 17 00:00:00 2001 From: Leon <31146334+ierehon1905@users.noreply.github.com> Date: Sun, 17 Oct 2021 15:41:13 +0300 Subject: [PATCH] enh(css) add support for hex color alpha channel (#3360) (#3362) --- CHANGES.md | 2 ++ src/languages/lib/css-shared.js | 2 +- test/markup/css/hex-colors.expect.txt | 19 +++++++++++++++++++ test/markup/css/hex-colors.txt | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/markup/css/hex-colors.expect.txt create mode 100644 test/markup/css/hex-colors.txt diff --git a/CHANGES.md b/CHANGES.md index 86dc83bf1f..f906cad1ec 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,7 @@ Grammars: - enh(nsis) add new NSIS commands (#3351) [idleberg][] - fix(nsis) set `case_insensitive` to `true` (#3351) [idleberg][] - fix(css/less/stylus/scss) highlight single-colon psuedo-elements properly (#3240) [zsoltlengyelit][] +- fix(css) add css hex color alpha support (#3360) [ierehon1905][] [Austin Schick]: https://github.com/austin-schick [Josh Goebel]: https://github.com/joshgoebel @@ -53,6 +54,7 @@ Grammars: [zsoltlengyelit]: github.com/zsoltlengyelit [Syb Wartna]:https://github.com/waarissyb [idleberg]: https://github.com/idleberg +[ierehon1905]: https://github.com/ierehon1905 ## Version 11.2.0 diff --git a/src/languages/lib/css-shared.js b/src/languages/lib/css-shared.js index 9c9d2a364a..933a484154 100644 --- a/src/languages/lib/css-shared.js +++ b/src/languages/lib/css-shared.js @@ -7,7 +7,7 @@ export const MODES = (hljs) => { BLOCK_COMMENT: hljs.C_BLOCK_COMMENT_MODE, HEXCOLOR: { scope: 'number', - begin: '#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})' + begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/ }, FUNCTION_DISPATCH: { className: "built_in", diff --git a/test/markup/css/hex-colors.expect.txt b/test/markup/css/hex-colors.expect.txt new file mode 100644 index 0000000000..062d05876c --- /dev/null +++ b/test/markup/css/hex-colors.expect.txt @@ -0,0 +1,19 @@ +.test-short { + color: #abc; +} + +.test-short-alpha { + color: #abcd; +} + +.test-long { + color: #aabbcc; +} + +.test-long-alpha { + color: #aabbccdd; +} + +.test-invalid { + color: #aabbccd; +} \ No newline at end of file diff --git a/test/markup/css/hex-colors.txt b/test/markup/css/hex-colors.txt new file mode 100644 index 0000000000..f74a3cec52 --- /dev/null +++ b/test/markup/css/hex-colors.txt @@ -0,0 +1,19 @@ +.test-short { + color: #abc; +} + +.test-short-alpha { + color: #abcd; +} + +.test-long { + color: #aabbcc; +} + +.test-long-alpha { + color: #aabbccdd; +} + +.test-invalid { + color: #aabbccd; +} \ No newline at end of file