Skip to content

Commit 02dd134

Browse files
committed
docs(bi-directional-links): rewrite with twoslash support
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
1 parent 263f7e0 commit 02dd134

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

  • docs/pages

‎docs/pages/en/integrations/markdown-it-bi-directional-links/index.md‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ In the VitePress configuration file (usually `docs/.vitepress/config.ts`, the fi
179179

180180
<!--@include: @/pages/en/snippets/details-colored-diff.md-->
181181

182-
```typescript
183-
import process from 'node:process' // [!code ++]
182+
```typescript twoslash
183+
import { cwd } from 'node:process' // [!code ++]
184184
import { defineConfigWithTheme } from 'vitepress'
185-
import { MarkdownItBiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
185+
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
186186
187187
export default defineConfigWithTheme({
188188
lang: 'en',
@@ -193,8 +193,8 @@ export default defineConfigWithTheme({
193193
},
194194
markdown: {
195195
config: (md) => {
196-
md.use(MarkdownItBiDirectionalLinks({ // [!code ++]
197-
dir: process.cwd(), // [!code ++]
196+
md.use(BiDirectionalLinks({ // [!code ++]
197+
dir: cwd(), // [!code ++]
198198
})) // [!code ++]
199199
},
200200
},
@@ -207,20 +207,23 @@ export default defineConfigWithTheme({
207207

208208
Import this plugin into the file where you can access the [`markdown-it`](https://github.com/markdown-it/markdown-it) instance, and use it as a `markdown-it` plugin:
209209

210-
```typescript
211-
import { MarkdownItBiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
210+
```typescript twoslash
211+
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
212212
```
213213
214214
Then you need to use the `use()` member methods from the `markdown-it` instance to use this plugin.
215215
With a options object that contains a `dir` field which is the root directory of your project supplied, the value for `dir` field can be obtained through `cwd()` function call that imported from either `process` or `node:process`:
216216
217-
```typescript
218-
import MarkdownItBiDirectionalLinks from '@nolebase/markdown-it-bi-directional-links'
219-
import { cwd } from 'process' // [!code ++]
217+
```typescript twoslash
218+
import type { MarkdownIt } from 'markdown-it'
219+
let markdownIt = null as MarkdownIt
220+
// ---cut---
221+
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
222+
import { cwd } from 'node:process' // [!code ++]
220223
221224
// Rest of the code...
222-
223-
markdownIt.use(MarkdownItBiDirectionalLinks({ // [!code ++]
224-
dir: process.cwd() // [!code ++]
225+
// @noErrors
226+
markdownIt.use(BiDirectionalLinks({ // [!code ++]
227+
dir: cwd() // [!code ++]
225228
})) // [!code ++]
226229
```

‎docs/pages/zh-CN/integrations/markdown-it-bi-directional-links/index.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ yarn add @nolebase/markdown-it-bi-directional-links -D
181181

182182
<!--@include: @/pages/zh-CN/snippets/details-colored-diff.md-->
183183

184-
```typescript
185-
import process from 'node:process' // [!code ++]
184+
```typescript twoslash
185+
import { cwd } from 'node:process' // [!code ++]
186186
import { defineConfigWithTheme } from 'vitepress'
187187
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
188188
@@ -196,7 +196,7 @@ export default defineConfigWithTheme({
196196
markdown: {
197197
config: (md) => {
198198
md.use(BiDirectionalLinks({ // [!code ++]
199-
dir: process.cwd(), // 注意这行不要漏掉了哦 // [!code ++]
199+
dir: cwd(), // 注意这行不要漏掉了哦 // [!code ++]
200200
})) // [!code ++]
201201
},
202202
},
@@ -209,19 +209,23 @@ export default defineConfigWithTheme({
209209

210210
在 [`markdown-it`](https://github.com/markdown-it/markdown-it) 的实例可被访问的地方先使用 `import` 语句将双向链接插件导入到文件中:
211211

212-
```typescript
212+
```typescript twoslash
213213
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links' // [!code ++]
214214
```
215215
216216
然后使用 `markdown-it` 实例的 `use()` 函数将导入后的 `MarkdownItBiDirectionalLinks` 作为插件使用,并配置一个包含有 `dir` 字段的对象,这个所谓的 `dir` 字段通常可以直接通过 `import` 语句导入来自 `process` 或者 `node:process` 包内的 `cwd()` 函数来获取:
217217
218-
```typescript
218+
```typescript twoslash
219+
import type { MarkdownIt } from 'markdown-it'
220+
let markdownIt = null as MarkdownIt
221+
// ---cut---
219222
import { BiDirectionalLinks } from '@nolebase/markdown-it-bi-directional-links'
220223
import { cwd } from 'process' // [!code ++]
221224
222225
// 中间剩余的其他代码...
223226

227+
// @noErrors
224228
markdownIt.use(BiDirectionalLinks({ // [!code ++]
225-
dir: process.cwd() // [!code ++]
229+
dir: cwd() // [!code ++]
226230
})) // [!code ++]
227231
```

0 commit comments

Comments
 (0)