Skip to content

Commit ed1a1a7

Browse files
committed
feat(twoslash): expose twoslasher option to be override
1 parent 426ffe2 commit ed1a1a7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/shikiji-twoslash/src/core.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function defaultTwoSlashOptions() {
2626
}
2727
}
2828

29-
export function createTransformer(runTwoslasher: typeof twoslasher) {
29+
export function createTransformerFactory(defaultTwoslasher: typeof twoslasher) {
3030
return function transformerTwoSlash(options: TransformerTwoSlashOptions = {}): ShikijiTransformer {
3131
const {
3232
langs = ['ts', 'tsx'],
@@ -36,6 +36,7 @@ export function createTransformer(runTwoslasher: typeof twoslasher) {
3636
json5: 'json',
3737
yml: 'yaml',
3838
},
39+
twoslasher = defaultTwoslasher,
3940
explicitTrigger = false,
4041
renderer = rendererClassic(),
4142
throws = true,
@@ -49,7 +50,7 @@ export function createTransformer(runTwoslasher: typeof twoslasher) {
4950

5051
if (filter(lang, code, shikijiOptions)) {
5152
shikijiOptions.mergeWhitespaces = false
52-
const twoslash = runTwoslasher(code, lang, twoslashOptions)
53+
const twoslash = twoslasher(code, lang, twoslashOptions)
5354
this.meta.twoslash = twoslash
5455
return twoslash.code
5556
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { twoslasher } from '@typescript/twoslash'
2-
import { createTransformer } from './core'
2+
import { createTransformerFactory } from './core'
33

44
export * from './core'
55

6-
export const transformerTwoSlash = createTransformer(twoslasher)
6+
export const transformerTwoSlash = createTransformerFactory(twoslasher)

packages/shikiji-twoslash/src/types.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { TwoSlashOptions, TwoSlashReturn } from '@typescript/twoslash'
1+
import type { TwoSlashOptions, TwoSlashReturn, twoslasher } from '@typescript/twoslash'
22
import type { CodeToHastOptions, ShikijiTransformerContext } from 'shikiji-core'
33
import type { Element, ElementContent, Text } from 'hast'
44

@@ -28,6 +28,10 @@ export interface TransformerTwoSlashOptions {
2828
* When specified, `langs` and `explicitTrigger` will be ignored
2929
*/
3030
filter?: (lang: string, code: string, options: CodeToHastOptions) => boolean
31+
/**
32+
* Custom instance of twoslasher function
33+
*/
34+
twoslasher?: typeof twoslasher
3135
/**
3236
* Options to pass to twoslash
3337
*/

0 commit comments

Comments
 (0)