Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix twoslash #1782

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ export default defineConfig({
transformerTwoslash({
twoslashOptions: {
// The @slidev/* installed in docs package are very old and should only be used in the homepage demo
vfsRoot: fileURLToPath(new URL('../../demo/starter/', import.meta.url)),
vfsRoot: fileURLToPath(import.meta.url),
compilerOptions: {
resolveJsonModule: true,
},
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/scripts/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { copy, remove } from 'fs-extra'

async function main() {
await remove('.vitepress/@slidev')
await copy('node_modules/@slidev', '.vitepress/@slidev', { dereference: true })
await copy('node_modules/@slidev-old', '.vitepress/@slidev', { dereference: true })
}

main()
8 changes: 8 additions & 0 deletions docs/custom/config-code-runners.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ By default, JavaScript, TypeScript runners are supported built-in. They run in t

Create `./setup/code-runners.ts` with the following content:

<!-- eslint-disable import/first -->

```ts twoslash
declare const executePythonCodeRemotely: (code: string) => Promise<string>
declare const sanitizeHtml: (html: string) => string
// ---cut---
import { defineCodeRunnersSetup } from '@slidev/types'

export default defineCodeRunnersSetup(() => {
Expand All @@ -35,6 +40,9 @@ export default defineCodeRunnersSetup(() => {
The second argument `ctx` is the runner context, which contains the following properties:

```ts twoslash
import type { CodeRunnerOutputs } from '@slidev/types'
import type { CodeToHastOptions } from 'shiki'
// ---cut---
export interface CodeRunnerContext {
/**
* Options passed to runner via the `runnerOptions` prop.
Expand Down
7 changes: 7 additions & 0 deletions docs/custom/config-context-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ Customize the context menu items in Slidev.

Create `./setup/context-menu.ts` with the following content:

<!-- eslint-disable import/first -->

```ts twoslash
// ---cut---
import { defineContextMenuSetup } from '@slidev/types'
import { useNav } from '@slidev/client'
import { computed } from 'vue'
// ---cut-start---
// @ts-expect-error missing types
// ---cut-end---
import Icon3DCursor from '~icons/carbon/3d-cursor'

export default defineContextMenuSetup((items) => {
Expand Down
11 changes: 6 additions & 5 deletions docs/custom/config-highlighter.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ If you want to add custom theme or language (TextMate grammar/themes in JSON), y
<!-- eslint-disable import/first-->

```ts twoslash
declare module '*.tmTheme.json' {
const value: any
export default value
}
// ---cut---
/* ./setup/shiki.ts */
import { defineShikiSetup } from '@slidev/types'
// ---cut-start---
// @ts-expect-error missing types
// ---cut-end---
import customTheme from './customTheme.tmTheme.json'
// ---cut-start---
// @ts-expect-error missing types
// ---cut-end---
import customLanguage from './customLanguage.tmLanguage.json'

export default defineShikiSetup(() => {
Expand Down
4 changes: 2 additions & 2 deletions docs/custom/config-parser.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configure Pre-Parser

::: info
Custom pre-parsers are not supposed to be used too often. Please only use it if you really want to have your custom syntax.
Custom pre-parsers are not supposed to be used too often. Usually you can use [Transformers](./config-transformers) for custom syntaxes.
:::

Slidev parses your presentation file (e.g. `slides.md`) in three steps:
Expand Down Expand Up @@ -162,7 +162,7 @@ import { definePreparserSetup } from '@slidev/types'
export default definePreparserSetup(() => {
return [
{
transformSlide(content, frontmatter) {
async transformSlide(content, frontmatter) {
if ('_scale' in frontmatter) {
return [
`<Transform :scale=${frontmatter._scale}>`,
Expand Down
3 changes: 3 additions & 0 deletions docs/custom/config-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default defineRoutesSetup((routes) => {
...routes,
{
path: '/my-page',
// ---cut-start---
// @ts-expect-error missing types
// ---cut-end---
component: () => import('../pages/my-page.vue'),
},
]
Expand Down
8 changes: 7 additions & 1 deletion docs/custom/config-vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ Slidev internally adds the following plugins to Vite:

To configure the built-in plugins listed above, create a `vite.config.ts` with the following content. Please note that Slidev has some [default configurations](https://github.com/slidevjs/slidev/blob/main/packages/slidev/node/vite/index.ts) for those plugins, this usage will override some of them, which may potentially cause the app to break. Please treat this as **an advanced feature**, and make sure you know what you are doing before moving on.

<!-- eslint-disable import/first -->

```ts twoslash
/// <reference types="@slidev/types" />
import type MarkdownIt from 'markdown-it'
declare const MyPlugin: (md: MarkdownIt) => void
// ---cut---
import { defineConfig } from 'vite'

export default defineConfig({
Expand All @@ -31,7 +37,7 @@ export default defineConfig({
/* markdown-it options */
markdownItSetup(md) {
/* custom markdown-it plugins */
md.use(/* ... */)
md.use(MyPlugin/* ... */)
},
},
/* options for other plugins */
Expand Down
5 changes: 5 additions & 0 deletions docs/custom/config-vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ Slidev uses [Vue 3](https://v3.vuejs.org/) to render the application on the clie

Create `./setup/main.ts` with the following content:

<!-- eslint-disable import/first -->

```ts twoslash
import type { Plugin } from 'vue'
declare const YourPlugin: Plugin
// ---cut---
import { defineAppSetup } from '@slidev/types'

export default defineAppSetup(({ app, router }) => {
Expand Down
11 changes: 7 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
"devDependencies": {
"@iconify/json": "^2.2.230",
"@shikijs/vitepress-twoslash": "^1.11.1",
"@slidev/client": "0.34.3",
"@slidev/parser": "0.34.3",
"@slidev/theme-default": "0.21.2",
"@slidev/types": "0.34.3",
"@slidev-old/client": "npm:@slidev/client@0.34.3",
"@slidev-old/parser": "npm:@slidev/parser@0.34.3",
"@slidev-old/theme-default": "npm:@slidev/theme-default@0.21.2",
"@slidev-old/types": "npm:@slidev/types@0.34.3",
"@slidev/client": "workspace:*",
"@slidev/parser": "workspace:*",
"@slidev/types": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.11",
"@unocss/reset": "^0.61.5",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"lint:fix": "nr lint --fix",
"typecheck": "vue-tsc --noEmit",
"docs": "pnpm -C docs run dev",
"docs:build": "pnpm -C docs run build && pnpm demo:build",
"docs:build": "pnpm run --filter {./docs}... build && pnpm demo:build",
"release": "bumpp package.json packages/*/package.json docs/package.json --all -x \"zx scripts/update-versions.mjs\"",
"test": "vitest test",
"prepare": "simple-git-hooks"
Expand Down
27 changes: 18 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading