File tree Expand file tree Collapse file tree 4 files changed +124
-2
lines changed
en/plugin/official-plugins
zh/plugin/official-plugins Expand file tree Collapse file tree 4 files changed +124
-2
lines changed Original file line number Diff line number Diff line change 1010 " preview" ,
1111 " playground" ,
1212 " rss" ,
13- " algolia"
13+ " algolia" ,
14+ " twoslash"
1415]
Original file line number Diff line number Diff line change 1+ # @rspress/plugin-twoslash <SourceCode href = " https://github.com/web-infra-dev/rspress/tree/main/packages/plugin-twoslash" />
2+
3+ import { SourceCode , PackageManagerTabs } from ' @rspress/core/theme' ;
4+
5+ Integration of [ Twoslash] ( https://github.com/twoslashes/twoslash ) 's Rspress Plugin for Automatically Generating Rich Code Blocks with Type Information.
6+
7+ ## Installation
8+
9+ <PackageManagerTabs command = " add @rspress/plugin-twoslash -D" />
10+
11+ ## Usage
12+
13+ ### 1. Register the plugin
14+
15+ ``` ts title="rspress.config.ts"
16+ import { defineConfig } from ' @rspress/core' ;
17+ import { pluginTwoslash } from ' @rspress/plugin-twoslash' ;
18+
19+ export default defineConfig ({
20+ plugins: [pluginTwoslash ()],
21+ });
22+ ```
23+
24+ ### 2. Write code blocks with twoslash
25+
26+ Use the special comments within TypeScript code blocks enables Twoslash features.
27+
28+ For more detailed usage, please refer to the [ Twoslash documentation] ( https://twoslash.netlify.app/guide/ ) .
29+
30+ #### Extract type
31+
32+ ``` ts
33+ const hi = ' Hello' ;
34+ const msg = ` ${hi }, world ` ;
35+ // ^?
36+ ```
37+
38+ #### Completions
39+
40+ ``` ts
41+ // @noErrors
42+ console .e ;
43+ // ^|
44+ ```
45+
46+ #### Highlighting
47+
48+ ``` ts
49+ function add(a : number , b : number ) {
50+ // ^^^
51+ return a + b ;
52+ }
53+ ```
54+
55+ #### Error
56+
57+ ``` ts
58+ // @noErrorValidation
59+ const str: string = 1 ;
60+ ```
Original file line number Diff line number Diff line change 1010 " preview" ,
1111 " playground" ,
1212 " rss" ,
13- " algolia"
13+ " algolia" ,
14+ " twoslash"
1415]
Original file line number Diff line number Diff line change 1+ # @rspress/plugin-twoslash <SourceCode href = " https://github.com/web-infra-dev/rspress/tree/main/packages/plugin-twoslash" />
2+
3+ import { SourceCode , PackageManagerTabs } from ' @rspress/core/theme' ;
4+
5+ 集成 [ Twoslash] ( https://github.com/twoslashes/twoslash ) 的 Rspress 插件,用于自动生成带有类型信息的丰富代码块。
6+
7+ ## 安装
8+
9+ <PackageManagerTabs command = " add @rspress/plugin-twoslash -D" />
10+
11+ ## 使用
12+
13+ ### 1. 注册插件
14+
15+ ``` ts title="rspress.config.ts"
16+ import { defineConfig } from ' @rspress/core' ;
17+ import { pluginTwoslash } from ' @rspress/plugin-twoslash' ;
18+
19+ export default defineConfig ({
20+ plugins: [pluginTwoslash ()],
21+ });
22+ ```
23+
24+ ### 2. 使用 Twoslash 编写代码块
25+
26+ 在 TypeScript 代码块中使用特殊注释来启用 Twoslash 功能。
27+
28+ 更详细的用法,请参考 [ Twoslash 文档] ( https://twoslash.netlify.app/guide/ ) 。
29+
30+ #### 提取类型
31+
32+ ``` ts
33+ const hi = ' Hello' ;
34+ const msg = ` ${hi }, world ` ;
35+ // ^?
36+ ```
37+
38+ #### 自动补全
39+
40+ ``` ts
41+ // @noErrors
42+ console .e ;
43+ // ^|
44+ ```
45+
46+ #### 高亮显示
47+
48+ ``` ts
49+ function add(a : number , b : number ) {
50+ // ^^^
51+ return a + b ;
52+ }
53+ ```
54+
55+ #### 错误提示
56+
57+ ``` ts
58+ // @noErrorValidation
59+ const str: string = 1 ;
60+ ```
You can’t perform that action at this time.
0 commit comments