Skip to content

Commit 834103f

Browse files
committed
docs: add twoslash support and improve code rendering
- Add twoslash code transformer for improved TypeScript code rendering - Update Markdown files to use twoslash syntax for code examples - Add custom theme to support twoslash floating window - Update package.json to include new dependencies
1 parent 697de20 commit 834103f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+819
-80
lines changed

docs/.vitepress/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import process from 'node:process'
33
import dotenv from 'dotenv'
44
import type { DefaultTheme } from 'vitepress'
55
import { defineConfig } from 'vitepress'
6+
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
67
import typedocSidebar from '../api/typedoc-sidebar.json'
78
import { version } from '../../package.json'
89
import { transDocsJson } from './utils'
@@ -54,6 +55,15 @@ export default defineConfig({
5455
},
5556
},
5657
},
58+
markdown: {
59+
codeTransformers: [
60+
transformerTwoslash(),
61+
] as any,
62+
theme: {
63+
light: 'vitesse-light',
64+
dark: 'vitesse-dark',
65+
},
66+
},
5767
})
5868

5969
function getSearchConfig(env: NodeJS.ProcessEnv): DefaultTheme.Config['search'] {

docs/.vitepress/theme/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { EnhanceAppContext } from 'vitepress'
2+
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
3+
import Theme from 'vitepress/theme'
4+
5+
import '@shikijs/vitepress-twoslash/style.css'
6+
7+
export default {
8+
extends: Theme,
9+
enhanceApp({ app }: EnhanceAppContext) {
10+
app.use(TwoslashFloatingVue as any)
11+
},
12+
}

docs/api/algorithm/functions/binarySearch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function binarySearch(arr, target): number;
3030

3131
## Example
3232

33-
```ts
33+
```ts twoslash
3434
import { binarySearch } from '@ryanuo/utils'
3535
const index = binarySearch([1, 2, 3, 4, 5], 3)
3636
console.log(index) // 2

docs/api/algorithm/functions/bubbleSort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function bubbleSort(arr): number[];
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { bubbleSort } from '@ryanuo/utils'
2929
const sorted = bubbleSort([5, 3, 8, 4, 2])
3030
console.log(sorted) // [2, 3, 4, 5, 8]

docs/api/algorithm/functions/fibonacciDP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function fibonacciDP(n): number;
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { fibonacciDP } from '@ryanuo/utils'
2929
console.log(fibonacciDP(10)) // 55
3030
```

docs/api/algorithm/functions/fibonacciRecursive.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function fibonacciRecursive(n): number;
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { fibonacciRecursive } from '@ryanuo/utils'
2929
console.log(fibonacciRecursive(10)) // 55
3030
```

docs/api/algorithm/functions/isPrime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function isPrime(num): boolean;
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { isPrime } from '@ryanuo/utils'
2929
console.log(isPrime(11)) // true
3030
console.log(isPrime(15)) // false

docs/api/algorithm/functions/quickSort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function quickSort(arr): number[];
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { quickSort } from '@ryanuo/utils'
2929
const sorted = quickSort([5, 3, 8, 4, 2])
3030
console.log(sorted) // [2, 3, 4, 5, 8]

docs/api/browser/functions/getUrlParams.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ An object of parsed parameters
2424

2525
## Example
2626

27-
```ts
27+
```ts twoslash
2828
import { getUrlParams } from '@ryanuo/utils'
2929
getUrlParams() // { a: '1', b: '2' }
3030
```

docs/api/browser/functions/getUrlParamsString.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The URL to which parameters will be added, defaults to the current page URL
2828

2929
## Example
3030

31-
```ts
31+
```ts twoslash
3232
import { getUrlParamsString } from '@ryanuo/utils'
3333
getUrlParamsString({ a: 1, b: 2 }) // '?a=1&b=2'
3434
getUrlParamsString({ a: 1, b: 2 }, 'https://www.example.com')

0 commit comments

Comments
 (0)