Skip to content

Commit 8af7d54

Browse files
authored
highlight using directives in code snippets (#2845)
1 parent 8574b5d commit 8af7d54

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

resources/js/hljs-scala3.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ function highlightDotty(hljs) {
221221
]
222222
}
223223

224+
// glob all non-whitespace characters as a "string"
225+
const DIRECTIVE_VALUE = {
226+
className: 'string',
227+
begin: /\S+/,
228+
}
229+
230+
// glob all non-whitespace characters as a "type", so that we can highlight differently to values
231+
const DIRECTIVE_KEY = {
232+
className: 'type',
233+
begin: /\S+/,
234+
}
235+
236+
// directives
237+
const USING_DIRECTIVE = hljs.COMMENT('//>', '\n', {
238+
contains: [
239+
{
240+
begin: /using /,
241+
end: /\s/,
242+
keywords: 'using',
243+
contains: [
244+
DIRECTIVE_KEY
245+
]
246+
},
247+
DIRECTIVE_VALUE,
248+
]
249+
})
250+
224251
// Documentation
225252
const SCALADOC = hljs.COMMENT('/\\*\\*', '\\*/', {
226253
contains: [
@@ -454,6 +481,7 @@ function highlightDotty(hljs) {
454481
NUMBER,
455482
CHAR,
456483
STRING,
484+
USING_DIRECTIVE,
457485
SCALADOC,
458486
hljs.C_LINE_COMMENT_MODE,
459487
hljs.C_BLOCK_COMMENT_MODE,

0 commit comments

Comments
 (0)