@@ -5,7 +5,9 @@ import process from 'node:process';
5
5
import path from 'node:path' ;
6
6
import ts from 'typescript' ;
7
7
import * as marked from 'marked' ;
8
- import { codeToHtml , createCssVariablesTheme } from 'shiki' ;
8
+ import { createHighlighterCore } from 'shiki/core' ;
9
+ import { createOnigurumaEngine } from 'shiki/engine/oniguruma' ;
10
+ import { createCssVariablesTheme } from 'shiki' ;
9
11
import { transformerTwoslash } from '@shikijs/twoslash' ;
10
12
import { SHIKI_LANGUAGE_MAP , slugify , smart_quotes , transform } from './utils' ;
11
13
@@ -43,6 +45,20 @@ if (!fs.existsSync(original_file)) {
43
45
hash_graph ( hash , original_file ) ;
44
46
const digest = hash . digest ( ) . toString ( 'base64' ) . replace ( / \/ / g, '-' ) ;
45
47
48
+ const highlighter = await createHighlighterCore ( {
49
+ themes : [ ] ,
50
+ langs : [
51
+ import ( '@shikijs/langs/javascript' ) ,
52
+ import ( '@shikijs/langs/typescript' ) ,
53
+ import ( '@shikijs/langs/html' ) ,
54
+ import ( '@shikijs/langs/css' ) ,
55
+ import ( '@shikijs/langs/bash' ) ,
56
+ import ( '@shikijs/langs/yaml' ) ,
57
+ import ( '@shikijs/langs/svelte' )
58
+ ] ,
59
+ engine : createOnigurumaEngine ( import ( 'shiki/wasm' ) )
60
+ } ) ;
61
+
46
62
/**
47
63
* Utility function to work with code snippet caching.
48
64
*
@@ -722,7 +738,7 @@ async function syntax_highlight({
722
738
723
739
if ( / ^ ( d t s | y a m l | y m l ) / . test ( language ) ) {
724
740
html = replace_blank_lines (
725
- await codeToHtml ( source , {
741
+ highlighter . codeToHtml ( source , {
726
742
lang : language === 'dts' ? 'ts' : language ,
727
743
theme
728
744
} )
@@ -737,7 +753,7 @@ async function syntax_highlight({
737
753
} ) ;
738
754
739
755
try {
740
- html = await codeToHtml ( prelude + redacted , {
756
+ html = highlighter . codeToHtml ( prelude + redacted , {
741
757
lang : language ,
742
758
theme,
743
759
transformers : check
@@ -833,7 +849,7 @@ async function syntax_highlight({
833
849
834
850
html = replace_blank_lines ( html ) ;
835
851
} else {
836
- const highlighted = await codeToHtml ( source , {
852
+ const highlighted = highlighter . codeToHtml ( source , {
837
853
lang : SHIKI_LANGUAGE_MAP [ language as keyof typeof SHIKI_LANGUAGE_MAP ] ,
838
854
theme
839
855
} ) ;
0 commit comments