Skip to content

Commit

Permalink
docs: add formula demo (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
kagol authored Sep 1, 2024
1 parent 77eb1ca commit 070033d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/docs/fluent-editor/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function sidebar() {
{ text: '@提醒', link: '/docs/mention' },
{ text: '插入表情', link: '/docs/emoji' },
{ text: '格式刷', link: '/docs/format-painter' },
{ text: '公式', link: '/docs/formula' },
]
}
]
Expand Down
36 changes: 36 additions & 0 deletions packages/docs/fluent-editor/demos/formula.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import FluentEditor from '@opentiny/fluent-editor'
import katex from 'katex'
import 'katex/dist/katex.min.css'
window.katex = katex
let editor
const TOOLBAR_CONFIG = [
[{ header: [] }],
['bold', 'italic', 'underline', 'link'],
[{ list: 'ordered' }, { list: 'bullet' }],
['clean'],
['formula'],
]
onMounted(() => {
// ssr compat, reference: https://vitepress.dev/guide/ssr-compat#importing-in-mounted-hook
import('@opentiny/fluent-editor').then((module) => {
const FluentEditor = module.default
editor = new FluentEditor('#editor', {
theme: 'snow',
modules: {
toolbar: TOOLBAR_CONFIG,
formula: true,
},
})
})
})
</script>

<template>
<div id="editor" />
</template>
8 changes: 8 additions & 0 deletions packages/docs/fluent-editor/docs/formula.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 公式

通过配置 `formula` 为 true,并配置工具栏按钮 `formula`,可以开启插入公式功能。

由于插入公式依赖 `KaTeX`,需要安装 `katex` 依赖包,并引入对应的样式。

:::demo src=demos/formula.vue
:::
3 changes: 2 additions & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"vitepress": "^1.3.2"
},
"dependencies": {
"@opentiny/fluent-editor": "workspace:^"
"@opentiny/fluent-editor": "workspace:^",
"katex": "^0.16.11"
}
}
16 changes: 15 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit 070033d

Please sign in to comment.