Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/plugin-twoslash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
},
"peerDependencies": {
"@rspress/core": "workspace:^2.0.0-rc.0",
"react": ">=18.0.0"
"react": ">=18.0.0",
"typescript": "^5.8.2"
},
"engines": {
"node": ">=18.0.0"
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-twoslash/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { gfmFromMarkdown } from 'mdast-util-gfm';
import { defaultHandlers, toHast } from 'mdast-util-to-hast';
import picocolors from 'picocolors';
import { removeTwoslashNotations } from 'twoslash';
import type { CompilerOptions } from 'typescript';

const staticPath = path.join(__dirname, '../static');

Expand Down Expand Up @@ -115,6 +116,10 @@ export interface PluginTwoslashOptions {
* @default true
*/
cache?: boolean;
/**
* TypeScript compiler options to use for Twoslash
*/
compilerOptions?: CompilerOptions;
}

/**
Expand All @@ -137,6 +142,9 @@ export function pluginTwoslash(options?: PluginTwoslashOptions): RspressPlugin {
transformerTwoslash({
explicitTrigger,
cache,
twoslashOptions: {
compilerOptions: options?.compilerOptions,
},
onShikiError: onError,
onTwoslashError: onError,
rendererRich: {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/en/plugin/official-plugins/twoslash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,12 @@ const str: string = 1;
The plugin accepts an object with the following type:

```ts twoslash
import { CompilerOptions } from 'typescript';
// ---cut-before---
export interface PluginTwoslashOptions {
explicitTrigger?: boolean;
cache?: boolean;
compilerOptions?: CompilerOptions;
}
```

Expand All @@ -148,3 +151,8 @@ export interface PluginTwoslashOptions {
### cache

`cache` is used to cache the TypeScript language servers based on compiler options when calling [createTwoslasher](https://twoslash.netlify.app/refs/api#createtwoslasher). Default is `true`.

### compilerOptions

`compilerOptions` is used to configure TypeScript compiler options for Twoslash.
This allows you to customize the TypeScript environment used for type checking and hover information in code blocks.
7 changes: 7 additions & 0 deletions website/docs/zh/plugin/official-plugins/twoslash.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,12 @@ const str: string = 1;
该插件接受一个对象,具有以下类型:

```ts twoslash
import { CompilerOptions } from 'typescript';
// ---cut-before---
export interface PluginTwoslashOptions {
explicitTrigger?: boolean;
cache?: boolean;
compilerOptions?: CompilerOptions;
}
```

Expand All @@ -158,3 +161,7 @@ export interface PluginTwoslashOptions {
### cache

`cache` 用于在 [createTwoslasher](https://twoslash.netlify.app/refs/api#createtwoslasher) 时根据编译器选项缓存 TypeScript 语言服务器。默认值为 `true`。

### compilerOptions

`compilerOptions` 用于配置 Twoslash 的 TypeScript 编译器选项。这允许您自定义用于代码块中类型检查和悬停信息的 TypeScript 环境。
Loading