From c209658d1cb855e6fe610332b7dbc0ff5ac82b81 Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Thu, 22 Jun 2023 11:07:05 +0200 Subject: [PATCH] highlight using directives in code snippets --- resources/js/hljs-scala3.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/resources/js/hljs-scala3.js b/resources/js/hljs-scala3.js index 0ba80087ef..e0be3758b8 100644 --- a/resources/js/hljs-scala3.js +++ b/resources/js/hljs-scala3.js @@ -221,6 +221,33 @@ function highlightDotty(hljs) { ] } + // glob all non-whitespace characters as a "string" + const DIRECTIVE_VALUE = { + className: 'string', + begin: /\S+/, + } + + // glob all non-whitespace characters as a "type", so that we can highlight differently to values + const DIRECTIVE_KEY = { + className: 'type', + begin: /\S+/, + } + + // directives + const USING_DIRECTIVE = hljs.COMMENT('//>', '\n', { + contains: [ + { + begin: /using /, + end: /\s/, + keywords: 'using', + contains: [ + DIRECTIVE_KEY + ] + }, + DIRECTIVE_VALUE, + ] + }) + // Documentation const SCALADOC = hljs.COMMENT('/\\*\\*', '\\*/', { contains: [ @@ -454,6 +481,7 @@ function highlightDotty(hljs) { NUMBER, CHAR, STRING, + USING_DIRECTIVE, SCALADOC, hljs.C_LINE_COMMENT_MODE, hljs.C_BLOCK_COMMENT_MODE,