Skip to content
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Documentations and guides on **[Sli.dev](https://sli.dev)**
- 🌈 [**Stylish**](https://sli.dev/guide/syntax.html#embedded-styles) - [Windi CSS](https://windicss.org/) on-demand utilities, easy-to-use embedded stylesheets
- 🤹 [**Interactive**](https://sli.dev/custom/directory-structure.html#components) - embedding Vue components seamlessly
- 🎙 [**Presenter Mode**](https://sli.dev/guide/presenter-mode.html) - use another window, or even your phone to control your slides
- 🧮 [**LaTeX**](https://sli.dev/demo/starter/6) - Built-in LaTeX math equations support
- 🧮 [**LaTeX**](https://sli.dev/guide/syntax.html#latex) - Built-in LaTeX math equations support
- 📰 [**Diagrams**](https://sli.dev/guide/syntax.html#diagrams) - Creates diagrams with textual descriptions
- 🌟 [**Icons**](https://sli.dev/guide/syntax.html#icons) - Access to icons from any iconset directly
- 💻 [**Editors**](https://sli.dev/guide/editors.html) - Integrated editor, or [extension for VS Code](https://github.com/slidevjs/slidev-vscode)
- 🎥 [**Recording**](https://sli.dev/guide/recording.html) - built-in recording and camera view
Expand Down Expand Up @@ -84,6 +85,7 @@ For a full example, you can check the [demo](https://github.com/slidevjs/slidev/
- [VueUse](https://vueuse.org) family - [`@vueuse/core`](https://github.com/vueuse/vueuse), [`@vueuse/head`](https://github.com/vueuse/head), [`@vueuse/motion`](https://github.com/vueuse/motion), etc.
- [Iconify](https://iconify.design/) - Iconsets collection.
- [KaTeX](https://katex.org/) - LaTeX math rendering.
- [Mermaid](https://mermaid-js.github.io/mermaid) - Textual Diagrams.

## Sponsors

Expand Down
4 changes: 3 additions & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ You can learn more about the rationale behind the project in the [Why Slidev](/g
- 🌈 [**Stylish**](/guide/syntax.html#embedded-styles) - [Windi CSS](https://windicss.org/) on-demand utilities, easy-to-use embedded stylesheets
- 🤹 [**Interactive**](/custom/directory-structure.html#components) - embedding Vue components seamlessly
- 🎙 [**Presenter Mode**](/guide/presenter-mode.html) - use another window, or even your phone to control your slides
- 🧮 [**LaTeX**](https://sli.dev/demo/starter/6) - Built-in LaTeX math equations support
- 🧮 [**LaTeX**](/guide/syntax.html#latex) - Built-in LaTeX math equations support
- 📰 [**Diagrams**](/guide/syntax.html#diagrams) - Creates diagrams with textual descriptions
- 🌟 [**Icons**](/guide/syntax.html#icons) - Access to icons from any iconset directly
- 💻 [**Editors**](/guide/editors.html) - Integrated editor, or [extension for VS Code](https://github.com/slidevjs/slidev-vscode)
- 🎥 [**Recording**](/guide/recording.html) - built-in recording and camera view
Expand All @@ -36,6 +37,7 @@ Slidev is made possible by combining these tools and technologies.
- [VueUse](https://vueuse.org) family - [`@vueuse/core`](https://github.com/vueuse/vueuse), [`@vueuse/head`](https://github.com/vueuse/head), [`@vueuse/motion`](https://github.com/vueuse/motion), etc.
- [Iconify](https://iconify.design/) - Iconsets collection.
- [KaTeX](https://katex.org/) - LaTeX math rendering.
- [Mermaid](https://mermaid-js.github.io/mermaid) - Textual Diagrams.

### Scaffolding Your First Presentation

Expand Down
29 changes: 28 additions & 1 deletion docs/guide/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,31 @@ $$
$$
```

Learn more: [Demo](https://sli.dev/demo/starter/6) | [KaTeX](https://katex.org/) | [`markdown-it-katex`](https://github.com/waylonflinn/markdown-it-katex).
Learn more: [Demo](https://sli.dev/demo/starter/7) | [KaTeX](https://katex.org/) | [`markdown-it-katex`](https://github.com/waylonflinn/markdown-it-katex)

## Diagrams

You can also create diagrams / graphs from textual descriptions in your Markdown, powered by [Mermaid](https://mermaid-js.github.io/mermaid).

Code blocks marked as `mermaid` will be converted to digrams, for example:

~~~md
//```mermaid
sequenceDiagram
Alice->John: Hello John, how are you?
Note over Alice,John: A typical interaction
//```
~~~

You can further pass an options object to it to specify the scaling and theming. The syntax of the object is a JavaScript object literal, you will need to add quotes (`'`) for strings and use comma (`,`) between keys.

~~~md
//```mermaid {theme: 'neutral', scale: 0.8}
graph TD
B[Text] --> C{Decision}
C -->|One| D[Result 1]
C -->|Two| E[Result 2]
//```
~~~

Learn more: [Demo](https://sli.dev/demo/starter/8) | [Mermaid](https://mermaid-js.github.io/mermaid)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@types/jest": "^26.0.23",
"@types/js-yaml": "^4.0.1",
"@types/markdown-it": "^12.0.1",
"@types/mermaid": "^8.2.5",
"@types/node": "^15.0.2",
"@types/prettier": "^2.2.3",
"@types/prismjs": "^1.16.5",
Expand Down
36 changes: 36 additions & 0 deletions packages/client/builtin/Mermaid.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Mermaid
(auto transformed, you don't need to use this component directly)

Usage:

```mermaid
pie
"Dogs" : 386
"Cats" : 85
"Rats" : 15
```
-->

<script setup lang="ts">
import { defineProps, computed, getCurrentInstance } from 'vue'
import { renderMermaid } from '../modules/mermaid'

const props = defineProps({
code: {
default: '',
},
scale: {
default: 1,
},
})

const vm = getCurrentInstance()
const html = computed(() => renderMermaid(props.code, vm?.attrs || {}))
</script>

<template>
<Transform :scale="scale">
<div v-html="html"></div>
</Transform>
</template>
2 changes: 2 additions & 0 deletions packages/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import './styles/code.css'
import 'virtual:windi-utilities.css'
import 'virtual:windi-devtools'

/* __body__ */

const app = createApp(App)
app.use(router)
app.use(createHead())
Expand Down
27 changes: 27 additions & 0 deletions packages/client/modules/mermaid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @ts-ignore
import mermaid from 'mermaid/dist/mermaid.min'
import { customAlphabet } from 'nanoid'
import { decode } from 'js-base64'

mermaid.startOnLoad = false
mermaid.initialize({ startOnLoad: false })

const nanoid = customAlphabet('abcedfghicklmn', 10)
const cache = new Map<string, string>()

export function renderMermaid(encoded: string, options: any) {
const _cache = cache.get(encoded)
if (_cache)
return _cache

mermaid.initialize({
startOnLoad: false,
theme: 'forest',
...options,
})
const code = decode(encoded)
const id = nanoid()
const svg = mermaid.render(id, code)
cache.set(encoded, svg)
return svg
}
66 changes: 46 additions & 20 deletions packages/create-app/template/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,39 @@ Check out [the guides](https://sli.dev/custom/#components) for more.
</div>
</div>


---
class: px-20
---

# Themes

Slidev comes with powerful theming support. Themes are able to provide styles, layouts, components, or even configurations for tools. Switching between themes by just **one edit** in your frontmatter:

<div grid="~ cols-2 gap-2" m="-t-2">

```yaml
---
theme: default
---
```

```yaml
---
theme: seriph
---
```

<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-default/01.png?raw=true">

<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-seriph/01.png?raw=true">

</div>

Read more about [How to use a theme](https://sli.dev/themes/use.html) and
check out the [Awesome Themes Gallery](https://sli.dev/themes/gallery.html).


---

# LaTeX
Expand Down Expand Up @@ -179,37 +212,30 @@ $$

[Learn more](https://sli.dev/guide/syntax#latex)

---
class: px-20
---

# Themes
# Diagrams

Slidev comes with powerful theming support. Themes are able to provide styles, layouts, components, or even configurations for tools. Switching between themes by just **one edit** in your frontmatter:
You can create diagrams / graphs from textual descriptions, directly in your Markdown.

<div grid="~ cols-2 gap-2" m="-t-2">
<div class="grid grid-cols-2 gap-4 pt-4 -mb-6">

```yaml
---
theme: default
---
```mermaid {scale: 0.9}
sequenceDiagram
Alice->John: Hello John, how are you?
Note over Alice,John: A typical interaction
```

```yaml
---
theme: seriph
---
```mermaid {theme: 'neutral', scale: 0.8}
graph TD
B[Text] --> C{Decision}
C -->|One| D[Result 1]
C -->|Two| E[Result 2]
```

<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-default/01.png?raw=true">

<img border="rounded" src="https://github.com/slidevjs/themes/blob/main/screenshots/theme-seriph/01.png?raw=true">

</div>

Read more about [How to use a theme](https://sli.dev/themes/use.html) and
check out the [Awesome Themes Gallery](https://sli.dev/themes/gallery.html).

Learn more about [the syntax](https://sli.dev/guide/syntax.html#diagrams)

---
layout: center
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function detectFeatures(code: string) {
katex: !!code.match(/\$.*?\$/) || !!code.match(/$\$\$/),
monaco: !!code.match(/{monaco.*}/),
tweet: !!code.match(/<Tweet\b/),
mermaid: !!code.match(/^```mermaid/m),
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/slidev/node/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function createEntryPlugin({ clientRoot, themeRoots, userRoot }: Resolved
async transform(code, id) {
if (id === mainEntry) {
const imports: string[] = []
const body: string[] = []

async function scanStyle(root: string) {
const styles = [
Expand All @@ -40,6 +41,7 @@ export function createEntryPlugin({ clientRoot, themeRoots, userRoot }: Resolved
await scanStyle(root)

code = code.replace('/* __imports__ */', imports.join('\n'))
code = code.replace('/* __body__ */', body.join('\n'))
return code
}

Expand Down
14 changes: 14 additions & 0 deletions packages/slidev/node/plugins/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export async function createMarkdownPlugin(
? transformMarkdownMonaco
: truncateMancoMark

code = transformMermaid(code)
code = monaco(code)
code = transformHighlighter(code)
code = transformPageCSS(code, id)
Expand Down Expand Up @@ -137,3 +138,16 @@ export function transformPageCSS(md: string, id: string) {

return result
}

/**
* Transform Mermaid code blocks (render done on client side)
*/
export default function transformMermaid(md: string): string {
return md
.replace(/^```mermaid\s*?({.*?})?\n([\s\S]+?)\n```/mg, (full, options = '', code = '') => {
code = code.trim()
options = options.trim() || '{}'
const encoded = base64.encode(code, true)
return `<Mermaid :code="'${encoded}'" v-bind="${options}" />`
})
}
4 changes: 3 additions & 1 deletion packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@
"markdown-it": "^12.0.6",
"markdown-it-katex": "^2.0.3",
"markdown-it-link-attributes": "^3.0.0",
"mermaid": "8.5.0",
"monaco-editor": "^0.23.0",
"nanoid": "^3.1.23",
"pdf-lib": "^1.16.0",
"prismjs": "^1.23.0",
"prompts": "^2.4.1",
"shiki": "^0.9.3",
"sirv": "^1.0.11",
"vite": "^2.3.0",
"vite-plugin-components": "^0.9.0",
"vite-plugin-components": "^0.8.4",
"vite-plugin-icons": "^0.5.0",
"vite-plugin-md": "^0.6.6",
"vite-plugin-remote-assets": "^0.2.2",
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface SlidevFeatureFlags {
katex: boolean
monaco: boolean
tweet: boolean
mermaid: boolean
}

export interface SlidevMarkdown {
Expand Down
Loading