svelte-highlight 7.11.0 → 7.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CopyButton.svelte +118 -0
- package/CopyButton.svelte.d.ts +138 -0
- package/HighlightStyle.svelte +25 -0
- package/HighlightStyle.svelte.d.ts +29 -0
- package/LangTag.svelte +10 -1
- package/LineNumbers.svelte +18 -6
- package/LineNumbers.svelte.d.ts +16 -0
- package/README.md +265 -7
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/langtag.css +1 -0
- package/languages/bibtex.d.ts +2 -0
- package/languages/bibtex.js +47 -0
- package/languages/bicep.d.ts +2 -0
- package/languages/bicep.js +72 -0
- package/languages/blade.d.ts +2 -0
- package/languages/blade.js +56 -0
- package/languages/caddy.d.ts +2 -0
- package/languages/caddy.js +59 -0
- package/languages/cairo.d.ts +2 -0
- package/languages/cairo.js +69 -0
- package/languages/clarity.d.ts +2 -0
- package/languages/clarity.js +55 -0
- package/languages/cue.d.ts +2 -0
- package/languages/cue.js +76 -0
- package/languages/cypher.d.ts +2 -0
- package/languages/cypher.js +61 -0
- package/languages/d2.d.ts +2 -0
- package/languages/d2.js +61 -0
- package/languages/dhall.d.ts +2 -0
- package/languages/dhall.js +74 -0
- package/languages/dotenv.d.ts +2 -0
- package/languages/dotenv.js +44 -0
- package/languages/fish.d.ts +2 -0
- package/languages/fish.js +68 -0
- package/languages/gleam.d.ts +2 -0
- package/languages/gleam.js +63 -0
- package/languages/groq.d.ts +2 -0
- package/languages/groq.js +69 -0
- package/languages/hcl.d.ts +2 -0
- package/languages/hcl.js +84 -0
- package/languages/index.d.ts +73 -1
- package/languages/index.js +36 -0
- package/languages/json5.d.ts +2 -0
- package/languages/json5.js +55 -0
- package/languages/jsonc.d.ts +2 -0
- package/languages/jsonc.js +36 -0
- package/languages/jsonnet.d.ts +2 -0
- package/languages/jsonnet.js +64 -0
- package/languages/liquid.d.ts +2 -0
- package/languages/liquid.js +55 -0
- package/languages/move.d.ts +2 -0
- package/languages/move.js +72 -0
- package/languages/nickel.d.ts +2 -0
- package/languages/nickel.js +65 -0
- package/languages/nushell.d.ts +2 -0
- package/languages/nushell.js +77 -0
- package/languages/odin.d.ts +2 -0
- package/languages/odin.js +78 -0
- package/languages/pkl.d.ts +2 -0
- package/languages/pkl.js +82 -0
- package/languages/prisma.d.ts +2 -0
- package/languages/prisma.js +70 -0
- package/languages/promql.d.ts +2 -0
- package/languages/promql.js +61 -0
- package/languages/pug.d.ts +2 -0
- package/languages/pug.js +50 -0
- package/languages/razor.d.ts +2 -0
- package/languages/razor.js +69 -0
- package/languages/rescript.d.ts +2 -0
- package/languages/rescript.js +71 -0
- package/languages/solidity.d.ts +2 -0
- package/languages/solidity.js +101 -0
- package/languages/starlark.d.ts +2 -0
- package/languages/starlark.js +54 -0
- package/languages/toml.d.ts +2 -0
- package/languages/toml.js +74 -0
- package/languages/v.d.ts +2 -0
- package/languages/v.js +90 -0
- package/languages/vyper.d.ts +2 -0
- package/languages/vyper.js +57 -0
- package/languages/wgsl.d.ts +2 -0
- package/languages/wgsl.js +56 -0
- package/languages/zig.d.ts +2 -0
- package/languages/zig.js +100 -0
- package/package.json +1 -1
- package/scoped.d.ts +11 -0
- package/scoped.js +276 -0
package/README.md
CHANGED
|
@@ -123,6 +123,107 @@ CSS StyleSheets can also be externally linked from a Content Delivery Network (C
|
|
|
123
123
|
</svelte:head>
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
+
### Scoping styles
|
|
127
|
+
|
|
128
|
+
Themes target global `.hljs` selectors. Add more than one and the last injected wins. That works when every block on the page shares one theme.
|
|
129
|
+
|
|
130
|
+
Reach for scoped styles when blocks on the same page need different themes: a style gallery, a side-by-side comparison, or a light snippet next to a dark one.
|
|
131
|
+
|
|
132
|
+
Wrap each `Highlight` in `HighlightStyle` to keep a theme on that block:
|
|
133
|
+
|
|
134
|
+
```svelte
|
|
135
|
+
<script>
|
|
136
|
+
import { Highlight, HighlightStyle } from "svelte-highlight";
|
|
137
|
+
import typescript from "svelte-highlight/languages/typescript";
|
|
138
|
+
import a11yDark from "svelte-highlight/styles/a11y-dark";
|
|
139
|
+
import github from "svelte-highlight/styles/github";
|
|
140
|
+
|
|
141
|
+
const code = "const add = (a: number, b: number) => a + b;";
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<HighlightStyle theme={a11yDark}>
|
|
145
|
+
<Highlight language={typescript} {code} />
|
|
146
|
+
</HighlightStyle>
|
|
147
|
+
|
|
148
|
+
<HighlightStyle theme={github}>
|
|
149
|
+
<Highlight language={typescript} {code} />
|
|
150
|
+
</HighlightStyle>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The component prefixes each selector with a scope class on the wrapper, so the theme only hits markup inside it.
|
|
154
|
+
|
|
155
|
+
`theme` is required. `scopeClass` defaults to a hash of the theme string. Pass your own, or bind it (`bind:scopeClass`) / read it from the slot (`let:scopeClass`).
|
|
156
|
+
|
|
157
|
+
For a page-wide theme, use `{@html theme}` as shown above.
|
|
158
|
+
|
|
159
|
+
## Styling with CSS variables
|
|
160
|
+
|
|
161
|
+
Every `Highlight` variant forwards `$$restProps` to its top-level element, so you can style the component using CSS variables without resorting to `:global` overrides or `!important`.
|
|
162
|
+
|
|
163
|
+
```svelte
|
|
164
|
+
<Highlight
|
|
165
|
+
language={typescript}
|
|
166
|
+
{code}
|
|
167
|
+
--border-radius="8px"
|
|
168
|
+
--max-width="40rem"
|
|
169
|
+
/>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Container variables
|
|
173
|
+
|
|
174
|
+
These apply to the outer container of every component (the `pre` element for `Highlight`, `HighlightAuto`, `HighlightSvelte`, and `LangTag`; the `div` element for `LineNumbers`).
|
|
175
|
+
|
|
176
|
+
| Variable | Description | Default value |
|
|
177
|
+
| :-------------- | :----------------------------------------- | :------------ |
|
|
178
|
+
| --border-radius | Border radius of the container | `0` |
|
|
179
|
+
| --width | Width of the container | `auto` |
|
|
180
|
+
| --max-width | Maximum width of the container | `none` |
|
|
181
|
+
| --overflow-x | Horizontal overflow behavior | `auto` |
|
|
182
|
+
| --overflow-y | Vertical overflow behavior | `auto` |
|
|
183
|
+
|
|
184
|
+
> [!NOTE]
|
|
185
|
+
> Because the container clips its content (`overflow` is not `visible` by default), setting `--border-radius` rounds the visible corners without any extra CSS.
|
|
186
|
+
|
|
187
|
+
### `LineNumbers` variables
|
|
188
|
+
|
|
189
|
+
| Variable | Description | Default value |
|
|
190
|
+
| :----------------------- | :------------------------------------------------ | :------------------------ |
|
|
191
|
+
| --line-number-color | Text color of the line numbers | `currentColor` |
|
|
192
|
+
| --border-color | Border color of the column of line numbers | `currentColor` |
|
|
193
|
+
| --highlighted-background | Background color of highlighted lines | `rgba(254, 241, 96, 0.2)` |
|
|
194
|
+
| --unhighlighted-opacity | Opacity of un-highlighted lines (focus mode) | `1` |
|
|
195
|
+
| --unhighlighted-filter | CSS filter for un-highlighted lines (focus mode) | `none` |
|
|
196
|
+
| --padding | Fallback padding for `--padding-left` / `--padding-right` | `1em` |
|
|
197
|
+
| --padding-left | Left padding for `td` elements | `var(--padding, 1em)` |
|
|
198
|
+
| --padding-right | Right padding for `td` elements | `var(--padding, 1em)` |
|
|
199
|
+
|
|
200
|
+
### `CopyButton` variables
|
|
201
|
+
|
|
202
|
+
| Variable | Description | Default value |
|
|
203
|
+
| :------------------- | :----------------------------------- | :------------ |
|
|
204
|
+
| --copy-top | Top offset of the button | `0.5em` |
|
|
205
|
+
| --copy-right | Right offset of the button | `0.5em` |
|
|
206
|
+
| --copy-size | Width and height of the button | `2em` |
|
|
207
|
+
| --copy-padding | Inner padding of the button | `0.5em` |
|
|
208
|
+
| --copy-background | Background color of the button | `inherit` |
|
|
209
|
+
| --copy-color | Foreground color of the button | `inherit` |
|
|
210
|
+
| --copy-border-radius | Border radius of the button | `4px` |
|
|
211
|
+
| --copy-border | Border of the button | `none` |
|
|
212
|
+
| --copy-z-index | Stacking order of the button | `2` |
|
|
213
|
+
|
|
214
|
+
### Language tag variables
|
|
215
|
+
|
|
216
|
+
These apply when `langtag` is set to `true`.
|
|
217
|
+
|
|
218
|
+
| Variable | Description | Default value |
|
|
219
|
+
| :---------------------- | :------------------------------ | :------------ |
|
|
220
|
+
| --langtag-top | Top position of the langtag | `0` |
|
|
221
|
+
| --langtag-right | Right position of the langtag | `0` |
|
|
222
|
+
| --langtag-background | Background color of the langtag | `inherit` |
|
|
223
|
+
| --langtag-color | Text color of the langtag | `inherit` |
|
|
224
|
+
| --langtag-border-radius | Border radius of the langtag | `0` |
|
|
225
|
+
| --langtag-padding | Padding of the langtag | `1em` |
|
|
226
|
+
|
|
126
227
|
## Svelte Syntax Highlighting
|
|
127
228
|
|
|
128
229
|
Use the `HighlightSvelte` component for Svelte syntax highlighting.
|
|
@@ -241,6 +342,24 @@ The line number starts at `1`. Customize this via the `startingLineNumber` prop.
|
|
|
241
342
|
|
|
242
343
|
Specify the lines to highlight using the `highlightedLines` prop. Indices start at zero.
|
|
243
344
|
|
|
345
|
+
```svelte
|
|
346
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
347
|
+
<LineNumbers {highlighted} highlightedLines={[0, 2, 3, 14]} />
|
|
348
|
+
</Highlight>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Use `--unhighlighted-opacity` or `--unhighlighted-filter` to de-emphasize the remaining lines and focus attention on the highlighted ones. Both only take effect when `highlightedLines` is non-empty.
|
|
352
|
+
|
|
353
|
+
```svelte
|
|
354
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
355
|
+
<LineNumbers
|
|
356
|
+
{highlighted}
|
|
357
|
+
highlightedLines={[0, 2, 3, 14]}
|
|
358
|
+
--unhighlighted-opacity="0.4"
|
|
359
|
+
/>
|
|
360
|
+
</Highlight>
|
|
361
|
+
```
|
|
362
|
+
|
|
244
363
|
Use `--highlighted-background` to customize the background color of highlighted lines.
|
|
245
364
|
|
|
246
365
|
```svelte
|
|
@@ -257,13 +376,18 @@ Use `--highlighted-background` to customize the background color of highlighted
|
|
|
257
376
|
|
|
258
377
|
Use `--style-props` to customize styles.
|
|
259
378
|
|
|
260
|
-
| Style prop | Description
|
|
261
|
-
| :----------------------- |
|
|
262
|
-
| --line-number-color | Text color of the line numbers
|
|
263
|
-
| --border-color | Border color of the column of line numbers
|
|
264
|
-
| --padding
|
|
265
|
-
| --padding-
|
|
266
|
-
| --
|
|
379
|
+
| Style prop | Description | Default value |
|
|
380
|
+
| :----------------------- | :------------------------------------------------------ | :------------------------ |
|
|
381
|
+
| --line-number-color | Text color of the line numbers | `currentColor` |
|
|
382
|
+
| --border-color | Border color of the column of line numbers | `currentColor` |
|
|
383
|
+
| --padding | Fallback padding for `--padding-left` / `--padding-right` | `1em` |
|
|
384
|
+
| --padding-left | Left padding for `td` elements | `var(--padding, 1em)` |
|
|
385
|
+
| --padding-right | Right padding for `td` elements | `var(--padding, 1em)` |
|
|
386
|
+
| --highlighted-background | Background color of highlighted lines | `rgba(254, 241, 96, 0.2)` |
|
|
387
|
+
| --unhighlighted-opacity | Opacity of un-highlighted lines (focus mode) | `1` |
|
|
388
|
+
| --unhighlighted-filter | CSS filter for un-highlighted lines (focus mode) | `none` |
|
|
389
|
+
|
|
390
|
+
See [Styling with CSS variables](#styling-with-css-variables) for the full list, including container-level variables like `--border-radius`, `--width`, and `--overflow-x`.
|
|
267
391
|
|
|
268
392
|
```svelte
|
|
269
393
|
<Highlight language={typescript} {code} let:highlighted>
|
|
@@ -274,6 +398,8 @@ Use `--style-props` to customize styles.
|
|
|
274
398
|
--padding-left={0}
|
|
275
399
|
--padding-right="3em"
|
|
276
400
|
--highlighted-background="#000"
|
|
401
|
+
--border-radius="8px"
|
|
402
|
+
--max-width="40rem"
|
|
277
403
|
/>
|
|
278
404
|
</Highlight>
|
|
279
405
|
```
|
|
@@ -303,6 +429,111 @@ With `HighlightAuto`:
|
|
|
303
429
|
</HighlightAuto>
|
|
304
430
|
```
|
|
305
431
|
|
|
432
|
+
## Copy Button
|
|
433
|
+
|
|
434
|
+
Compose the `CopyButton` component alongside `Highlight` to add a copy-to-clipboard button. Wrap both in a relatively-positioned container so the button can be positioned over the code block.
|
|
435
|
+
|
|
436
|
+
By default, it copies the `code` using the native [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText) and shows a transient "copied" state. The button renders a copy icon that swaps to a checkmark on success; the `text` / `copiedText` props set the `aria-label` for each state. Clicks are ignored while in the "copied" state, so no duplicate copy fires.
|
|
437
|
+
|
|
438
|
+
```svelte
|
|
439
|
+
<script>
|
|
440
|
+
import { Highlight, CopyButton } from "svelte-highlight";
|
|
441
|
+
import typescript from "svelte-highlight/languages/typescript";
|
|
442
|
+
import atomOneDark from "svelte-highlight/styles/atom-one-dark";
|
|
443
|
+
|
|
444
|
+
const code = "const add = (a: number, b: number) => a + b";
|
|
445
|
+
</script>
|
|
446
|
+
|
|
447
|
+
<svelte:head>
|
|
448
|
+
{@html atomOneDark}
|
|
449
|
+
</svelte:head>
|
|
450
|
+
|
|
451
|
+
<div style="position: relative">
|
|
452
|
+
<Highlight language={typescript} {code} />
|
|
453
|
+
<CopyButton {code} />
|
|
454
|
+
</div>
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Custom Copy Behavior
|
|
458
|
+
|
|
459
|
+
Pass a `copy` function to override the default copy behavior. It receives the `code` to copy and may be async (return a promise); the "copied" state is shown only once it resolves. Clicks are ignored while a copy is in flight, so a slow async `copy` can't fire duplicates.
|
|
460
|
+
|
|
461
|
+
```svelte
|
|
462
|
+
<script>
|
|
463
|
+
function copy(code) {
|
|
464
|
+
navigator.clipboard.writeText(code);
|
|
465
|
+
console.log("Copied:", code);
|
|
466
|
+
}
|
|
467
|
+
</script>
|
|
468
|
+
|
|
469
|
+
<CopyButton {code} {copy} />
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
The component dispatches a `copy` event on success and an `error` event if the copy behavior throws.
|
|
473
|
+
|
|
474
|
+
```svelte
|
|
475
|
+
<CopyButton
|
|
476
|
+
{code}
|
|
477
|
+
on:copy={(e) => console.log(e.detail.code)}
|
|
478
|
+
on:error={(e) => console.error(e.detail.error)}
|
|
479
|
+
/>
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
### Custom Button Content
|
|
483
|
+
|
|
484
|
+
Provide custom button content using the default slot to replace the default icons. The slot exposes a `copied` boolean and a `copying` boolean (`true` while an async `copy` is in flight), so you can render a pending state for slow copy functions.
|
|
485
|
+
|
|
486
|
+
```svelte
|
|
487
|
+
<CopyButton {code} let:copied let:copying>
|
|
488
|
+
{#if copying}Copying…{:else if copied}Copied!{:else}Copy{/if}
|
|
489
|
+
</CopyButton>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Custom Styles
|
|
493
|
+
|
|
494
|
+
Use `--copy-*` style props to customize the button.
|
|
495
|
+
|
|
496
|
+
```svelte
|
|
497
|
+
<CopyButton
|
|
498
|
+
{code}
|
|
499
|
+
--copy-background="rgba(255, 255, 255, 0.1)"
|
|
500
|
+
--copy-color="#fff"
|
|
501
|
+
--copy-border-radius="8px"
|
|
502
|
+
/>
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### With Line Numbers
|
|
506
|
+
|
|
507
|
+
Compose `CopyButton` with `LineNumbers` by wrapping both in a relatively-positioned container.
|
|
508
|
+
|
|
509
|
+
```svelte
|
|
510
|
+
<div style="position: relative">
|
|
511
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
512
|
+
<LineNumbers {highlighted} />
|
|
513
|
+
</Highlight>
|
|
514
|
+
<CopyButton {code} />
|
|
515
|
+
</div>
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### With Language Tag
|
|
519
|
+
|
|
520
|
+
When using a language tag alongside `CopyButton`, offset `--langtag-top` and `--langtag-right` so the tag sits to the left of the button (the copy button defaults to `--copy-top: 0.5em`, `--copy-right: 0.5em`, and `--copy-size: 2em`).
|
|
521
|
+
|
|
522
|
+
```svelte
|
|
523
|
+
<div style="position: relative">
|
|
524
|
+
<Highlight
|
|
525
|
+
language={typescript}
|
|
526
|
+
{code}
|
|
527
|
+
langtag
|
|
528
|
+
--langtag-top="0"
|
|
529
|
+
--langtag-right="3em"
|
|
530
|
+
--langtag-padding="0.25em 0.5em"
|
|
531
|
+
--langtag-font-size="0.75em"
|
|
532
|
+
/>
|
|
533
|
+
<CopyButton {code} />
|
|
534
|
+
</div>
|
|
535
|
+
```
|
|
536
|
+
|
|
306
537
|
## Language Targeting
|
|
307
538
|
|
|
308
539
|
All `Highlight` components apply a `data-language` attribute on the codeblock containing the language name.
|
|
@@ -503,6 +734,33 @@ In the example below, the `HighlightAuto` component and injected styles are dyna
|
|
|
503
734
|
|
|
504
735
|
`$$restProps` are forwarded to the top-level `div` element.
|
|
505
736
|
|
|
737
|
+
### `CopyButton`
|
|
738
|
+
|
|
739
|
+
#### Props
|
|
740
|
+
|
|
741
|
+
| Name | Type | Default value |
|
|
742
|
+
| :--------- | :----------------------------------------- | :------------------------------------------- |
|
|
743
|
+
| code | `string` | N/A (required) |
|
|
744
|
+
| copy | `(code: string) => void \| Promise<void>` | `(code) => navigator.clipboard.writeText(code)` |
|
|
745
|
+
| timeout | `number` | `2000` |
|
|
746
|
+
| text | `string` | `"Copy"` |
|
|
747
|
+
| copiedText | `string` | `"Copied!"` |
|
|
748
|
+
|
|
749
|
+
`$$restProps` are forwarded to the top-level `button` element.
|
|
750
|
+
|
|
751
|
+
#### Dispatched Events
|
|
752
|
+
|
|
753
|
+
- **on:copy**: fired after a successful copy, with `{ code }`
|
|
754
|
+
- **on:error**: fired if the copy behavior throws, with `{ error }`
|
|
755
|
+
|
|
756
|
+
```svelte
|
|
757
|
+
<CopyButton
|
|
758
|
+
{code}
|
|
759
|
+
on:copy={(e) => console.log(e.detail.code)}
|
|
760
|
+
on:error={(e) => console.error(e.detail.error)}
|
|
761
|
+
/>
|
|
762
|
+
```
|
|
763
|
+
|
|
506
764
|
### `HighlightSvelte`
|
|
507
765
|
|
|
508
766
|
#### Props
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
export { default as CopyButton } from "./CopyButton.svelte";
|
|
1
2
|
export { default as Highlight, default } from "./Highlight.svelte";
|
|
2
3
|
export { default as HighlightAuto } from "./HighlightAuto.svelte";
|
|
4
|
+
export { default as HighlightStyle } from "./HighlightStyle.svelte";
|
|
3
5
|
export { default as HighlightSvelte } from "./HighlightSvelte.svelte";
|
|
4
6
|
export { default as LineNumbers } from "./LineNumbers.svelte";
|
|
5
7
|
export type { LanguageName, LanguageType } from "./languages";
|
package/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
export { default as CopyButton } from "./CopyButton.svelte";
|
|
1
2
|
export { default, default as Highlight } from "./Highlight.svelte";
|
|
2
3
|
export { default as HighlightAuto } from "./HighlightAuto.svelte";
|
|
4
|
+
export { default as HighlightStyle } from "./HighlightStyle.svelte";
|
|
3
5
|
export { default as HighlightSvelte } from "./HighlightSvelte.svelte";
|
|
4
6
|
export { default as LineNumbers } from "./LineNumbers.svelte";
|
package/langtag.css
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
2
|
+
function defineBibtex(hljs) {
|
|
3
|
+
// Only braces/quotes that follow `field =` are values; the outer entry
|
|
4
|
+
// braces stay plain so the body's fields can still be highlighted.
|
|
5
|
+
// Brace-delimited values can nest, so this mode references itself.
|
|
6
|
+
/** @type {import("highlight.js").Mode} */
|
|
7
|
+
const BRACED_VALUE = { className: "string", begin: /\{/, end: /\}/ };
|
|
8
|
+
BRACED_VALUE.contains = [BRACED_VALUE];
|
|
9
|
+
|
|
10
|
+
const QUOTED_VALUE = {
|
|
11
|
+
className: "string",
|
|
12
|
+
begin: /"/,
|
|
13
|
+
end: /"/,
|
|
14
|
+
contains: [hljs.BACKSLASH_ESCAPE],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const NUMBER = { className: "number", begin: /\b\d+\b/ };
|
|
18
|
+
|
|
19
|
+
const FIELD = {
|
|
20
|
+
begin: [/\b[a-zA-Z][a-zA-Z0-9_-]*/, /\s*/, /=/],
|
|
21
|
+
beginScope: { 1: "attr", 3: "operator" },
|
|
22
|
+
end: /(?=,|\}|\n)/,
|
|
23
|
+
contains: [BRACED_VALUE, QUOTED_VALUE, NUMBER],
|
|
24
|
+
relevance: 0,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const ENTRY = {
|
|
28
|
+
className: "keyword",
|
|
29
|
+
begin: /@[a-zA-Z]+/,
|
|
30
|
+
relevance: 0,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: "BibTeX",
|
|
35
|
+
aliases: ["bibtex", "bib"],
|
|
36
|
+
case_insensitive: true,
|
|
37
|
+
contains: [hljs.COMMENT(/%/, /$/), ENTRY, FIELD],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @type {import("highlight.js").LanguageFn} */
|
|
42
|
+
function register(hljs) {
|
|
43
|
+
return defineBibtex(hljs);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const bibtex = { name: "bibtex", register };
|
|
47
|
+
export default bibtex;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const BICEP_KEYWORDS =
|
|
2
|
+
"targetScope resource module param var output existing for in if func type import metadata assert provider extends with using as";
|
|
3
|
+
|
|
4
|
+
const BICEP_TYPES = "string int bool object array secureString secureObject";
|
|
5
|
+
|
|
6
|
+
const BICEP_LITERALS = "true false null";
|
|
7
|
+
|
|
8
|
+
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
9
|
+
function defineBicep(hljs) {
|
|
10
|
+
const NUMBER = {
|
|
11
|
+
className: "number",
|
|
12
|
+
begin: /\b\d+\b/,
|
|
13
|
+
relevance: 0,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const INTERPOLATION = {
|
|
17
|
+
className: "subst",
|
|
18
|
+
begin: /\$\{/,
|
|
19
|
+
end: /\}/,
|
|
20
|
+
keywords: { keyword: BICEP_KEYWORDS, literal: BICEP_LITERALS },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const STRING = {
|
|
24
|
+
className: "string",
|
|
25
|
+
variants: [
|
|
26
|
+
{ begin: /'''/, end: /'''/ },
|
|
27
|
+
{
|
|
28
|
+
begin: /'/,
|
|
29
|
+
end: /'/,
|
|
30
|
+
contains: [hljs.BACKSLASH_ESCAPE, INTERPOLATION],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const DECORATOR = {
|
|
36
|
+
className: "meta",
|
|
37
|
+
begin: /@[a-zA-Z_]\w*/,
|
|
38
|
+
relevance: 0,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const RESOURCE_TYPE = {
|
|
42
|
+
className: "type",
|
|
43
|
+
begin: /'[A-Za-z][\w.]+\/[\w./]+@[\d-]+'/,
|
|
44
|
+
relevance: 0,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
name: "Bicep",
|
|
49
|
+
aliases: ["bicep"],
|
|
50
|
+
keywords: {
|
|
51
|
+
keyword: BICEP_KEYWORDS,
|
|
52
|
+
type: BICEP_TYPES,
|
|
53
|
+
literal: BICEP_LITERALS,
|
|
54
|
+
},
|
|
55
|
+
contains: [
|
|
56
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
57
|
+
hljs.C_BLOCK_COMMENT_MODE,
|
|
58
|
+
DECORATOR,
|
|
59
|
+
RESOURCE_TYPE,
|
|
60
|
+
STRING,
|
|
61
|
+
NUMBER,
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @type {import("highlight.js").LanguageFn} */
|
|
67
|
+
function register(hljs) {
|
|
68
|
+
return defineBicep(hljs);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const bicep = { name: "bicep", register };
|
|
72
|
+
export default bicep;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import xmlRegister from "highlight.js/lib/languages/xml";
|
|
2
|
+
|
|
3
|
+
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
4
|
+
function defineBlade(hljs) {
|
|
5
|
+
const VARIABLE = {
|
|
6
|
+
className: "variable",
|
|
7
|
+
begin: /\$+[A-Za-z_]\w*/,
|
|
8
|
+
relevance: 0,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const STRING = {
|
|
12
|
+
className: "string",
|
|
13
|
+
variants: [
|
|
14
|
+
{ begin: /"/, end: /"/ },
|
|
15
|
+
{ begin: /'/, end: /'/ },
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const DIRECTIVE = {
|
|
20
|
+
className: "keyword",
|
|
21
|
+
begin: /@[a-zA-Z]\w*/,
|
|
22
|
+
relevance: 10,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const COMMENT = hljs.COMMENT(/\{\{--/, /--\}\}/);
|
|
26
|
+
|
|
27
|
+
const RAW_ECHO = {
|
|
28
|
+
className: "template-variable",
|
|
29
|
+
begin: /\{!!/,
|
|
30
|
+
end: /!!\}/,
|
|
31
|
+
contains: [VARIABLE, STRING, hljs.NUMBER_MODE],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const ECHO = {
|
|
35
|
+
className: "template-variable",
|
|
36
|
+
begin: /\{\{-?/,
|
|
37
|
+
end: /-?\}\}/,
|
|
38
|
+
contains: [VARIABLE, STRING, hljs.NUMBER_MODE],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
name: "Blade",
|
|
43
|
+
aliases: ["blade"],
|
|
44
|
+
subLanguage: "xml",
|
|
45
|
+
contains: [COMMENT, DIRECTIVE, RAW_ECHO, ECHO],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** @type {import("highlight.js").LanguageFn} */
|
|
50
|
+
function register(hljs) {
|
|
51
|
+
hljs.registerLanguage("xml", xmlRegister);
|
|
52
|
+
return defineBlade(hljs);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const blade = { name: "blade", register };
|
|
56
|
+
export default blade;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const CADDY_DIRECTIVES =
|
|
2
|
+
"reverse_proxy file_server root encode tls header header_down header_up redir respond route handle handle_path handle_errors rewrite uri log basicauth basic_auth forward_auth php_fastcgi try_files bind import templates request_body push map vars metrics tracing acme_server abort error method bcrypt invoke";
|
|
3
|
+
|
|
4
|
+
const CADDY_GLOBAL =
|
|
5
|
+
"admin auto_https debug http_port https_port grace_period default_sni order storage acme_ca acme_dns email on_demand_tls local_certs skip_install_trust";
|
|
6
|
+
|
|
7
|
+
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
8
|
+
function defineCaddy(hljs) {
|
|
9
|
+
const PLACEHOLDER = {
|
|
10
|
+
className: "variable",
|
|
11
|
+
begin: /\{[a-zA-Z0-9_.$>-]+\}/,
|
|
12
|
+
relevance: 0,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const MATCHER = {
|
|
16
|
+
className: "symbol",
|
|
17
|
+
begin: /@[a-zA-Z_][\w-]*/,
|
|
18
|
+
relevance: 0,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const SITE_ADDRESS = {
|
|
22
|
+
className: "attr",
|
|
23
|
+
begin: /^\s*(?:https?:\/\/)?(?:[a-zA-Z0-9*.-]+)(?::\d+)?(?=\s*\{)/,
|
|
24
|
+
relevance: 0,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const SNIPPET = {
|
|
28
|
+
className: "title",
|
|
29
|
+
begin: /^\s*\([\w-]+\)/,
|
|
30
|
+
relevance: 0,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
name: "Caddyfile",
|
|
35
|
+
aliases: ["caddy", "caddyfile"],
|
|
36
|
+
case_insensitive: false,
|
|
37
|
+
keywords: {
|
|
38
|
+
keyword: CADDY_DIRECTIVES,
|
|
39
|
+
built_in: CADDY_GLOBAL,
|
|
40
|
+
},
|
|
41
|
+
contains: [
|
|
42
|
+
hljs.HASH_COMMENT_MODE,
|
|
43
|
+
hljs.QUOTE_STRING_MODE,
|
|
44
|
+
SNIPPET,
|
|
45
|
+
SITE_ADDRESS,
|
|
46
|
+
MATCHER,
|
|
47
|
+
PLACEHOLDER,
|
|
48
|
+
{ className: "number", begin: /\b\d+\b/, relevance: 0 },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @type {import("highlight.js").LanguageFn} */
|
|
54
|
+
function register(hljs) {
|
|
55
|
+
return defineCaddy(hljs);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const caddy = { name: "caddy", register };
|
|
59
|
+
export default caddy;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const CAIRO_KEYWORDS =
|
|
2
|
+
"fn let mut const if else loop while for return match struct enum trait impl mod use pub extern type ref in of as self Self break continue where dyn move box nopanic implicits";
|
|
3
|
+
|
|
4
|
+
const CAIRO_TYPES =
|
|
5
|
+
"felt252 u8 u16 u32 u64 u128 u256 usize i8 i16 i32 i64 i128 bool Array Span Option Result ContractAddress ClassHash ByteArray";
|
|
6
|
+
|
|
7
|
+
const CAIRO_LITERALS = "true false";
|
|
8
|
+
|
|
9
|
+
/** @param {import("highlight.js").HLJSApi} hljs */
|
|
10
|
+
function defineCairo(hljs) {
|
|
11
|
+
const NUMBER = {
|
|
12
|
+
className: "number",
|
|
13
|
+
variants: [
|
|
14
|
+
{ begin: /\b0[xX][0-9a-fA-F][0-9a-fA-F_]*\b/ },
|
|
15
|
+
{ begin: /\b0[oO][0-7][0-7_]*\b/ },
|
|
16
|
+
{ begin: /\b0[bB][01][01_]*\b/ },
|
|
17
|
+
{
|
|
18
|
+
begin:
|
|
19
|
+
/\b\d[\d_]*(?:_(?:felt252|u8|u16|u32|u64|u128|u256|usize|i8|i16|i32|i64|i128))?\b/,
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
relevance: 0,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const ATTRIBUTE = {
|
|
26
|
+
className: "meta",
|
|
27
|
+
begin: /#!?\[/,
|
|
28
|
+
end: /\]/,
|
|
29
|
+
relevance: 5,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const TYPE = {
|
|
33
|
+
className: "type",
|
|
34
|
+
begin: /\b[A-Z]\w*/,
|
|
35
|
+
relevance: 0,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const FUNCTION = {
|
|
39
|
+
begin: [/\bfn/, /\s+/, /[a-z_]\w*/],
|
|
40
|
+
beginScope: { 1: "keyword", 3: "title.function" },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
name: "Cairo",
|
|
45
|
+
aliases: ["cairo"],
|
|
46
|
+
keywords: {
|
|
47
|
+
keyword: CAIRO_KEYWORDS,
|
|
48
|
+
type: CAIRO_TYPES,
|
|
49
|
+
literal: CAIRO_LITERALS,
|
|
50
|
+
},
|
|
51
|
+
contains: [
|
|
52
|
+
hljs.C_LINE_COMMENT_MODE,
|
|
53
|
+
hljs.C_BLOCK_COMMENT_MODE,
|
|
54
|
+
hljs.QUOTE_STRING_MODE,
|
|
55
|
+
ATTRIBUTE,
|
|
56
|
+
FUNCTION,
|
|
57
|
+
TYPE,
|
|
58
|
+
NUMBER,
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @type {import("highlight.js").LanguageFn} */
|
|
64
|
+
function register(hljs) {
|
|
65
|
+
return defineCairo(hljs);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const cairo = { name: "cairo", register };
|
|
69
|
+
export default cairo;
|