remons-markdown-editor 1.0.0-beta.2 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +12 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/readme.md +61 -3
package/readme.md
CHANGED
|
@@ -30,6 +30,7 @@ export default function App() {
|
|
|
30
30
|
| onChange | (value: string) => void | - | 内容变更回调 |
|
|
31
31
|
| showPreview | boolean | true | 是否显示预览面板 |
|
|
32
32
|
| fullscreen | boolean | false | 是否显示全屏按钮 |
|
|
33
|
+
| previewOptions | PreviewOptions | - | 预览渲染配置,类型继承自 `RenderMarkdownProps` |
|
|
33
34
|
|
|
34
35
|
### MarkdownEditorRef
|
|
35
36
|
|
|
@@ -37,9 +38,67 @@ export default function App() {
|
|
|
37
38
|
|--------|----------|------|
|
|
38
39
|
| getContent | () => string | 获取当前编辑器内容 |
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
### PreviewOptions
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
预览渲染配置,类型继承自 `RenderMarkdownProps`(来自 `remons-render-markdown`),并扩展了 `languages` 字段:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import type { RenderMarkdownProps } from 'remons-render-markdown'
|
|
47
|
+
|
|
48
|
+
export type PreviewOptions = Omit<RenderMarkdownProps, 'content'> & {
|
|
49
|
+
languages?: Record<string, any> | null | undefined
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| 属性名 | 类型 | 默认值 | 说明 |
|
|
54
|
+
|--------|------|--------|------|
|
|
55
|
+
| languages | Record<string, any> | - | 自定义代码高亮语言配置 |
|
|
56
|
+
| customRenderers | MarkdownPlugin[] | - | 自定义 markdown-it 渲染插件 |
|
|
57
|
+
| excludedSelectors | string[] | - | 图片预览排除名单 |
|
|
58
|
+
| isSlotMermaid | boolean | - | 是否使用 slot 方式渲染 mermaid |
|
|
59
|
+
| isShowCollapsed | boolean | - | 是否显示代码折叠 |
|
|
60
|
+
| defaultCollapsed | boolean | - | 默认识否折叠代码 |
|
|
61
|
+
| showBackTop | boolean | - | 是否显示返回顶部 |
|
|
62
|
+
| isPrintPreview | boolean | - | 是否为打印模式 |
|
|
63
|
+
| mermaidDebounce | number | - | Mermaid 渲染防抖延迟(ms) |
|
|
64
|
+
| cdn | Record<string, string> | - | 自定义 CDN 配置 |
|
|
65
|
+
| chartConfig | (text: string) => string | - | 渲染前文本修改函数 |
|
|
66
|
+
|
|
67
|
+
更多配置请参考 [remons-render-markdown](https://github.com/liRemons/render-markdown)。
|
|
68
|
+
|
|
69
|
+
## 使用示例
|
|
70
|
+
|
|
71
|
+
### 自定义预览配置
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { MarkdownEditor } from 'remons-markdown-editor'
|
|
75
|
+
import type { PreviewOptions } from 'remons-markdown-editor'
|
|
76
|
+
import { languagesCommon } from 'remons-render-markdown'
|
|
77
|
+
import 'remons-markdown-editor/style.css'
|
|
78
|
+
|
|
79
|
+
function App() {
|
|
80
|
+
const previewOptions: PreviewOptions = {
|
|
81
|
+
// 自定义高亮语言(在 languagesCommon 基础上扩展)
|
|
82
|
+
languages: {
|
|
83
|
+
...languagesCommon,
|
|
84
|
+
// 添加自定义语言配置
|
|
85
|
+
},
|
|
86
|
+
// 自定义 markdown-it 插件,可使用 remons-markdown-plugins 按需导入
|
|
87
|
+
// 参考 https://github.com/liRemons/markdown-plugin
|
|
88
|
+
customRenderers: [
|
|
89
|
+
(md) => md.use(yourCustomPlugin)
|
|
90
|
+
],
|
|
91
|
+
// 禁用 mermaid slot 渲染
|
|
92
|
+
isSlotMermaid: false,
|
|
93
|
+
// 自定义排除选择器
|
|
94
|
+
excludedSelectors: ['.my-custom-class'],
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return <MarkdownEditor previewOptions={previewOptions} />
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 自定义容器
|
|
43
102
|
|
|
44
103
|
```tsx
|
|
45
104
|
import { MarkdownEditor, useRegisterToolbar } from 'remons-markdown-editor'
|
|
@@ -61,7 +120,6 @@ const schema = {
|
|
|
61
120
|
}
|
|
62
121
|
|
|
63
122
|
export default function App() {
|
|
64
|
-
// 单个注册
|
|
65
123
|
useRegisterToolbar(schema)
|
|
66
124
|
return <MarkdownEditor />
|
|
67
125
|
}
|