Markdown MD 编辑器
基本用法
自定义渲染
纯渲染模式
单列渲染模式
配置图片文件上传
checkbox 渲染
数学公式 渲染
PlantUML 渲染
配置快速提示
TOC目录渲染
mermaid 渲染
EditorMd 参数
参数名 | 类型 | 默认值 | 说明 |
---|---|---|---|
v-model | string | '' | 编辑器内容双向绑定 |
options | object | {} | 编辑器初始化时,自定义配置,可参考CodeMirror Options |
base-url | string | -- | 设置渲染到 html 时,为相对 url 添加的 baseUrl |
custom-parse | (html: string) => string | -- | 自定义对渲染后的 html 处理,需要接收渲染后的 html,返回自定义处理后的 html |
md-rules | object | {} | 设置 markdown 对字符串的处理方式, 可参考markdown-it |
md-plugins | MdPlugin[] | -- | 设置 markdown-it 插件 |
hintConfig | MdHintConfig[] | -- | 设置 快速提示 配置 |
mode | 'editonly' | 'readonly' | 'normal' | 'normal' | 只写/只读/双栏显示模式选择,默认 'normal' 双栏模式显示 |
custom-renderer-rules | ICustomRenderRule[] | [] | 自定义 markdown 对节点的渲染方式,每条规则需要指定对应节点 key,并自定义渲染函数 |
custom-xss-rules | ICustomXssRule[] | [] | 自定义 xss 对某种 tag 的过滤方式,每条规则需要指定 tag, 并给出需要加入白名单的属性数组 |
placeholder | string | '' | 编辑器无内容是的提示信息 |
fullscreen-z-index | number | 10 | 编辑器全屏状态的 z-index |
image-upload-to-server | boolean | false | 是否打开图片自定义上传开关(打开后将将监听图片的复制,toolbar 图片功能上传,传出事件回调) |
EditorMd 事件
事件名 | 回调参数 | 说明 | 跳转 Demo |
---|---|---|---|
after-editor-init | Function(instance: object) | 编辑器初始化事件,返回编辑器对象 | |
content-change | Function(content: string) | 编辑器内容改变事件,返回当前内容 | |
preview-content-change | Function() | 预览内容改变时触发 | |
image-upload | Function({file, callback}) | 打开图片上传开关后,图片上传事件回调,返回文件内容与 callback 函数 | |
checked-change | Function(content: string) | plugins添加checkbox后,预览checkbox checked状态改变回调 |
MdRender 参数
参数名 | 类型 | 默认值 | 说明 | 跳转 Demo |
---|---|---|---|---|
base-url | string | -- | 设置渲染到 html 时,为相对 url 添加 baseUrl | |
custom-parse | (html: string) => string | -- | 自定义对渲染后的 html 处理,需要接受渲染后的 html,返回自定义处理后的 html | |
md-rules | object | {} | 设置 markdown 对字符串的处理方式, 可参考markdown-it | |
custom-renderer-rules | ICustomRenderRule[] | [] | 设置 markdown 对字符串的处理方式, 可参考markdown-it | |
custom-xss-rules | ICustomXssRule[] | [] | 自定义 xss 对某种 tag 的过滤方式,每条规则需要指定 tag,并给出需要加入白名单的属性数组 |
MdRender 事件
事件名 | 回调参数 | 说明 | 跳转 Demo |
---|---|---|---|
md-render-change | Function(string) | 内容改变时触发,返回对应 html 渲染结果字段 | |
checked-change | Function(content: string) | plugins添加checkbox后,预览checkbox checked状态改变回调 |
ICustomRenderRule
interface ICustomRenderRule {
key: string;
value: Function;
}
ICustomXssRule
interface ICustomXssRule {
key: string;
value: string[];
}
MdPlugin
export interface MdPlugin {
plugin: any;
opts?: Object;
}
HintConfig
export interface HintConfigItem {
handler: (obj: { callback: (replaceText: string) => void; cursorHint: string; prefix: string }) => void;
}
export interface HintConfig {
throttleTime: number; // 触发提示事件debounceTime(ms),默认300
[key: string]: HintConfigItem; // key为触发提示前缀配置
}