Skip to content

Commit c06f4a8

Browse files
authored
Merge pull request #5 from slidevjs/sync-43ba9b51
docs(en): merge docs/main into docs-vn/main @ 43ba9b5
2 parents 4b377ab + f430d6d commit c06f4a8

Some content is hidden

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

82 files changed

+10059
-1129
lines changed

builtin/cli.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Slidev CLI
2+
3+
`@slidev/cli` exposes a binary called `slidev` that you can use to develop, build, and export your slides.
4+
5+
## Prerequisites
6+
7+
To use the CLI, you can either install `@slidev/cli` globally or install it locally in your Node.js project. If you created your project with `npm init slidev`, the CLI is already installed locally.
8+
9+
::: warning
10+
Usually `npx slidev` is not supported because the package name is actually `@slidev/cli`.
11+
:::
12+
13+
The CLI options of the commands obey the following conventions:
14+
15+
- the value of the option can be passed after a space or a `=` character:
16+
17+
Example: `slidev --port 8080` is equivalent to `slidev --port=8080`
18+
19+
- `true` can be omitted for boolean options:
20+
21+
Example: `slidev --open` is equivalent to `slidev --open true`
22+
23+
::: info
24+
25+
If you use npm, please don't forget to add `--` before the options to pass them to Slidev:
26+
27+
```bash
28+
npm run slidev -- --remote --port 8080 --open
29+
```
30+
31+
:::
32+
33+
## `slidev [entry]` {#dev}
34+
35+
Start a local server for Slidev.
36+
37+
- `[entry]` (`string`, default: `slides.md`): path to the markdown file containing your slides.
38+
39+
Options:
40+
41+
- `--port`, `-p` (`number`, default: `3030`): port number.
42+
- `--open`, `-o` (`boolean`, default: `false`): open in the browser.
43+
- `--remote [password]` (`string`): listen to the public host and enable remote control, if a value is passed then the presenter mode is private and only accessible by passing the given password in the URL query `password` parameter.
44+
- `--bind` (`string`, default: `0.0.0.0`): specify which IP addresses the server should listen on in the remote mode.
45+
- `--log` (`'error', 'warn', 'info', 'silent'`, default: `'warn'`): Log level.
46+
- `--force`, `-f` (`boolean`, default: `false`): force the optimizer to ignore the cache and re-bundle.
47+
- `--theme`, `-t` (`string`): override theme.
48+
49+
## `slidev build [entry]` {#build}
50+
51+
Build a hostable SPA. See <LinkInline link="guide/hosting" /> for more details.
52+
53+
- `[entry]` (`string`, default: `slides.md`): path to the slides markdown file.
54+
55+
Options:
56+
57+
- `--out`, `-o` (`string`, default: `dist`): output directory
58+
- `--base` (`string`, default: `/`): base URL (see https://vitejs.dev/config/shared-options.html#base)
59+
- `--download` (`boolean`, default: `false`): allow the download of the slides as a PDF inside the SPA
60+
- `--theme`, `-t` (`string`): override theme
61+
62+
## `slidev export [...entry]` {#export}
63+
64+
Export slides to PDF (or other format). See <LinkInline link="guide/exporting" /> for more details.
65+
66+
- `[entry]` (`string`, default: `slides.md`): path to the slides markdown entry.
67+
68+
Options:
69+
70+
- `--output` (`string`, default: use `exportFilename` (see https://sli.dev/custom/#frontmatter-configures) or use `[entry]-export`): path to the output.
71+
- `--format` (`'pdf', 'png', 'pptx', 'md'`, default: `'pdf'`): output format.
72+
- `--timeout` (`number`, default: `30000`): timeout for rendering the print page (see https://playwright.dev/docs/api/class-page#page-goto).
73+
- `--range` (`string`): page ranges to export (example: `'1,4-5,6'`).
74+
- `--dark` (`boolean`, default: `false`): export as dark theme.
75+
- `--with-clicks`, `-c` (`boolean`, default: `false`): export pages for every click animation (see https://sli.dev/guide/animations.html#click-animation).
76+
- `--theme`, `-t` (`string`): override theme.
77+
- `--omit-background` (`boolean`, default: `false`): remove the default browser background
78+
79+
## `slidev format [entry]` {#format}
80+
81+
Format the markdown file. Note that this won't format the content of the slides, only the organization of the markdown file.
82+
83+
- `[entry]` (`string`, default: `slides.md`): path to the slides markdown entry.
84+
85+
## `slidev theme [subcommand]` {#theme}
86+
87+
Theme-related operations.
88+
89+
Subcommands:
90+
91+
- `eject [entry]`: Eject the current theme into the local file system. See <LinkInline link="features/eject-theme" />.
92+
- `[entry]` (`string`, default: `slides.md`): path to the slides markdown entry.
93+
- Options:
94+
- `--dir` (`string`, default: `theme`): the output dir.
95+
- `--theme`, `-t` (`string`): override theme.

components.d.ts

+2-11
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,11 @@ declare module 'vue' {
1111
AddonInfo: typeof import('./.vitepress/theme/components/AddonInfo.vue')['default']
1212
Arrow: typeof import('./node_modules/@slidev/client/builtin/Arrow.vue')['default']
1313
AutoFitText: typeof import('./node_modules/@slidev/client/builtin/AutoFitText.vue')['default']
14-
'Carbon:chevronLeft': typeof import('~icons/carbon/chevron-left')['default']
15-
'Carbon:chevronRight': typeof import('~icons/carbon/chevron-right')['default']
16-
'Carbon:close': typeof import('~icons/carbon/close')['default']
17-
'Carbon:filterRemove': typeof import('~icons/carbon/filter-remove')['default']
18-
'Carbon:logoGithub': typeof import('~icons/carbon/logo-github')['default']
19-
'Carbon:logoTwitter': typeof import('~icons/carbon/logo-twitter')['default']
20-
'Carbon:presentationFile': typeof import('~icons/carbon/presentation-file')['default']
21-
'Carbon:reset': typeof import('~icons/carbon/reset')['default']
22-
'Carbon:search': typeof import('~icons/carbon/search')['default']
23-
'Carbon:tag': typeof import('~icons/carbon/tag')['default']
24-
'Carbon:video': typeof import('~icons/carbon/video')['default']
2514
CarbonApps: typeof import('~icons/carbon/apps')['default']
2615
CarbonArrowLeft: typeof import('~icons/carbon/arrow-left')['default']
2716
CarbonArrowRight: typeof import('~icons/carbon/arrow-right')['default']
2817
CarbonBadge: typeof import('~icons/carbon/badge')['default']
18+
CarbonDocumentPdf: typeof import('~icons/carbon/document-pdf')['default']
2919
CarbonDownload: typeof import('~icons/carbon/download')['default']
3020
CarbonEdit: typeof import('~icons/carbon/edit')['default']
3121
CarbonInformation: typeof import('~icons/carbon/information')['default']
@@ -36,6 +26,7 @@ declare module 'vue' {
3626
CarbonPen: typeof import('~icons/carbon/pen')['default']
3727
CarbonSettingsAdjust: typeof import('~icons/carbon/settings-adjust')['default']
3828
CarbonSun: typeof import('~icons/carbon/sun')['default']
29+
CarbonTextAnnotationToggle: typeof import('~icons/carbon/text-annotation-toggle')['default']
3930
CarbonUserAvatar: typeof import('~icons/carbon/user-avatar')['default']
4031
CarbonUserSpeaker: typeof import('~icons/carbon/user-speaker')['default']
4132
CarbonVideo: typeof import('~icons/carbon/video')['default']

custom/config-code-runners.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Configure Code Runners
2+
3+
<Environment type="client" />
4+
5+
Define code runners for custom languages in your Monaco Editor.
6+
7+
By default, JavaScript, TypeScript runners are supported built-in. They run in the browser **without** a sandbox environment. If you want more advanced integrations, you can provide your own code runner that sends the code to a remote server, runs in a Web Worker, or anything, up to you.
8+
9+
Create `./setup/code-runners.ts` with the following content:
10+
11+
<!-- eslint-disable import/first -->
12+
13+
```ts twoslash
14+
declare const executePythonCodeRemotely: (code: string) => Promise<string>
15+
declare const sanitizeHtml: (html: string) => string
16+
// ---cut---
17+
import { defineCodeRunnersSetup } from '@slidev/types'
18+
19+
export default defineCodeRunnersSetup(() => {
20+
return {
21+
async python(code, ctx) {
22+
// Somehow execute the code and return the result
23+
const result = await executePythonCodeRemotely(code)
24+
return {
25+
text: result
26+
}
27+
},
28+
html(code, ctx) {
29+
return {
30+
html: sanitizeHtml(code)
31+
}
32+
},
33+
// or other languages, key is the language id
34+
}
35+
})
36+
```
37+
38+
## Runner Context
39+
40+
The second argument `ctx` is the runner context, which contains the following properties:
41+
42+
```ts twoslash
43+
import type { CodeRunnerOutputs } from '@slidev/types'
44+
import type { CodeToHastOptions } from 'shiki'
45+
// ---cut---
46+
export interface CodeRunnerContext {
47+
/**
48+
* Options passed to runner via the `runnerOptions` prop.
49+
*/
50+
options: Record<string, unknown>
51+
/**
52+
* Highlight code with shiki.
53+
*/
54+
highlight: (code: string, lang: string, options?: Partial<CodeToHastOptions>) => string
55+
/**
56+
* Use (other) code runner to run code.
57+
*/
58+
run: (code: string, lang: string) => Promise<CodeRunnerOutputs>
59+
}
60+
```
61+
62+
## Runner Output
63+
64+
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.
65+
66+
## Additional Runner Dependencies
67+
68+
By default, Slidev will scan the Markdown source and automatically import the necessary dependencies for the code runners. If you want to manually import dependencies, you can use the `monacoRunAdditionalDeps` option in the slide frontmatter:
69+
70+
```yaml
71+
monacoRunAdditionalDeps:
72+
- ./path/to/dependency
73+
- lodash-es
74+
```
75+
76+
::: tip
77+
The paths are resolved relative to the `snippets` directory. And the names of the deps should be exactly the same as the imported ones in the code.
78+
:::

custom/config-context-menu.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Configure Context Menu
2+
3+
<Environment type="client" />
4+
5+
Customize the context menu items in Slidev.
6+
7+
Create `./setup/context-menu.ts` with the following content:
8+
9+
<!-- eslint-disable import/first -->
10+
11+
```ts twoslash
12+
// ---cut---
13+
import { useNav } from '@slidev/client'
14+
import { defineContextMenuSetup } from '@slidev/types'
15+
import { computed } from 'vue'
16+
// ---cut-start---
17+
// @ts-expect-error missing types
18+
// ---cut-end---
19+
import Icon3DCursor from '~icons/carbon/3d-cursor'
20+
21+
export default defineContextMenuSetup((items) => {
22+
const { isPresenter } = useNav()
23+
return computed(() => [
24+
...items.value,
25+
{
26+
small: false,
27+
icon: Icon3DCursor, // if `small` is `true`, only the icon is shown
28+
label: 'Custom Menu Item', // or a Vue component
29+
action() {
30+
alert('Custom Menu Item Clicked!')
31+
},
32+
disabled: isPresenter.value,
33+
},
34+
])
35+
})
36+
```
37+
38+
This will append a new menu item to the context menu.
39+
40+
To disable context menu globally, set `contextMenu` to `false` in the frontmatter. `contextMenu` can also be set to `dev` or `build` to only enable the context menu in development or build mode.

custom/config-fonts.md

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Configure Fonts
2+
3+
While you can use HTML and CSS to customize the fonts and style for your slides as you want, Slidev also provides a convenient way to use them effortlessly.
4+
5+
In your frontmatter, configure as the following:
6+
7+
```yaml
8+
---
9+
fonts:
10+
# basically the text
11+
sans: Robot
12+
# use with `font-serif` css class from UnoCSS
13+
serif: Robot Slab
14+
# for code blocks, inline code, etc.
15+
mono: Fira Code
16+
---
17+
```
18+
19+
And that's all.
20+
21+
Fonts will be **imported automatically from [Google Fonts](https://fonts.google.com/)**. That means you can use any fonts available on Google Fonts directly.
22+
23+
## Local Fonts
24+
25+
By default, Slidev assumes all the fonts specified via `fonts` configurations come from Google Fonts. If you want to use local fonts, specify the `fonts.local` to opt-out the auto-importing.
26+
27+
```yaml
28+
---
29+
fonts:
30+
# like font-family in css, you can use `,` to separate multiple fonts for fallback
31+
sans: 'Helvetica Neue,Robot'
32+
# mark 'Helvetica Neue' as local font
33+
local: Helvetica Neue
34+
---
35+
```
36+
37+
## Weights & Italic
38+
39+
By default, Slidev imports three weights `200`,`400`,`600` for each font. You can configure them by:
40+
41+
```yaml
42+
---
43+
fonts:
44+
sans: Robot
45+
# default
46+
weights: '200,400,600'
47+
# import italic fonts, default `false`
48+
italic: false
49+
---
50+
```
51+
52+
This configuration applies to all web fonts. For more fine-grained controls of each font's weights, you will need to manually import them with [HTML](/custom/directory-structure.html#index-html) and CSS.
53+
54+
## Fallback Fonts
55+
56+
For most of the scenarios, you only need to specify the "special font" and Slidev will append the fallback fonts for you, for example:
57+
58+
```yaml
59+
---
60+
fonts:
61+
sans: Robot
62+
serif: Robot Slab
63+
mono: Fira Code
64+
---
65+
```
66+
67+
will result in
68+
69+
<!-- eslint-skip -->
70+
71+
```css
72+
.font-sans {
73+
font-family: "Robot",ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";
74+
}
75+
.font-serif {
76+
font-family: "Robot Slab",ui-serif,Georgia,Cambria,"Times New Roman",Times,serif;
77+
}
78+
.font-mono {
79+
font-family: "Fira Code",ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
80+
}
81+
```
82+
83+
If you want to disable the fallback fonts, configure as the following:
84+
85+
```yaml
86+
---
87+
fonts:
88+
mono: 'Fira Code, monospace'
89+
fallbacks: false
90+
---
91+
```
92+
93+
## Providers
94+
95+
- Options: `google` | `none`
96+
- Default: `google`
97+
98+
Currently, only Google Fonts is supported, we are planning to add more providers in the future. Specify to `none` will disable the auto-importing feature entirely and treat all the fonts locally.
99+
100+
```yaml
101+
---
102+
fonts:
103+
provider: none
104+
---
105+
```

0 commit comments

Comments
 (0)