Commit ed1a1a7 1 parent 426ffe2 commit ed1a1a7 Copy full SHA for ed1a1a7
File tree 3 files changed +10
-5
lines changed
packages/shikiji-twoslash/src
3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ export function defaultTwoSlashOptions() {
26
26
}
27
27
}
28
28
29
- export function createTransformer ( runTwoslasher : typeof twoslasher ) {
29
+ export function createTransformerFactory ( defaultTwoslasher : typeof twoslasher ) {
30
30
return function transformerTwoSlash ( options : TransformerTwoSlashOptions = { } ) : ShikijiTransformer {
31
31
const {
32
32
langs = [ 'ts' , 'tsx' ] ,
@@ -36,6 +36,7 @@ export function createTransformer(runTwoslasher: typeof twoslasher) {
36
36
json5 : 'json' ,
37
37
yml : 'yaml' ,
38
38
} ,
39
+ twoslasher = defaultTwoslasher ,
39
40
explicitTrigger = false ,
40
41
renderer = rendererClassic ( ) ,
41
42
throws = true ,
@@ -49,7 +50,7 @@ export function createTransformer(runTwoslasher: typeof twoslasher) {
49
50
50
51
if ( filter ( lang , code , shikijiOptions ) ) {
51
52
shikijiOptions . mergeWhitespaces = false
52
- const twoslash = runTwoslasher ( code , lang , twoslashOptions )
53
+ const twoslash = twoslasher ( code , lang , twoslashOptions )
53
54
this . meta . twoslash = twoslash
54
55
return twoslash . code
55
56
}
Original file line number Diff line number Diff line change 1
1
import { twoslasher } from '@typescript/twoslash'
2
- import { createTransformer } from './core'
2
+ import { createTransformerFactory } from './core'
3
3
4
4
export * from './core'
5
5
6
- export const transformerTwoSlash = createTransformer ( twoslasher )
6
+ export const transformerTwoSlash = createTransformerFactory ( twoslasher )
Original file line number Diff line number Diff line change 1
- import type { TwoSlashOptions , TwoSlashReturn } from '@typescript/twoslash'
1
+ import type { TwoSlashOptions , TwoSlashReturn , twoslasher } from '@typescript/twoslash'
2
2
import type { CodeToHastOptions , ShikijiTransformerContext } from 'shikiji-core'
3
3
import type { Element , ElementContent , Text } from 'hast'
4
4
@@ -28,6 +28,10 @@ export interface TransformerTwoSlashOptions {
28
28
* When specified, `langs` and `explicitTrigger` will be ignored
29
29
*/
30
30
filter ?: ( lang : string , code : string , options : CodeToHastOptions ) => boolean
31
+ /**
32
+ * Custom instance of twoslasher function
33
+ */
34
+ twoslasher ?: typeof twoslasher
31
35
/**
32
36
* Options to pass to twoslash
33
37
*/
You can’t perform that action at this time.
0 commit comments