Skip to content

Commit

Permalink
docs: update code runner docs (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX authored Mar 8, 2024
1 parent a7918eb commit ed61a3a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/custom/config-code-runners.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ export default defineCodeRunnersSetup(() => {
}
})
```

## Runner Context

The second argument `ctx` is the runner context, which contains the following properties:

```ts
export interface CodeRunnerContext {
/**
* Options passed to runner via the `runnerOptions` prop.
*/
options: Record<string, unknown>
/**
* Highlight code with shiki.
*/
highlight: (code: string, lang: string, options?: Partial<CodeToHastOptions>) => Promise<string>
/**
* Use (other) code runner to run code.
*/
run: (code: string, lang: string) => Promise<CodeRunnerOutputs>
}
```

## Runner Output

The runner can either return a text or HTML output, or an element to be mounted. Refer to https://github.com/slidevjs/slidev/blob/main/packages/types/src/code-runner.ts for more details.
9 changes: 9 additions & 0 deletions packages/types/src/code-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ import type { CodeToHastOptions } from 'shiki'
import type { Arrayable, Awaitable } from '@antfu/utils'

export interface CodeRunnerContext {
/**
* Options passed to runner via the `runnerOptions` prop.
*/
options: Record<string, unknown>
/**
* Highlight code with shiki.
*/
highlight: (code: string, lang: string, options?: Partial<CodeToHastOptions>) => Promise<string>
/**
* Use (other) code runner to run code.
*/
run: (code: string, lang: string) => Promise<CodeRunnerOutputs>
}

Expand Down

0 comments on commit ed61a3a

Please sign in to comment.