扫一扫分享
Minditor 是一个既注重最终用户编辑体验,又注重开发者体验的块级富文本编辑器。它有以下特点:
npm i minditor
Minditor 本身的可以渲染在任意的 dom 节点中。对外没有任何的布局、样式等要求.
如果你只是用来渲染最简单的文字。可以直接使用下面的方式来渲染:
import {
Code, Grid,Heading,InlineImageBlock,InlineCode,Link,OLItem,Paragraph,Text,ULItem,InlineImageBlock
} from "minditor";
const rootElement = document.getElementById('root')!
const types = {
Paragraph,Text,Heading,OLItem,ULItem,InlineCode,Code,Link,Grid,Image: InlineImageBlock
}
const data = {
name: 'MyDoc',
children: [{
type: 'Paragraph',
content: [{type:'Text', value: 'This is my first document.'}]
}]
}
const doc = new Document(rootElement, data, types)
doc.render()
对于需要完整 Plugin,希望视图匡高自动适应外部 container 的场景,我们推荐使用 scaffold 来创建视图:
import {
Code,
createBlockTool,
createRangeTool,
createSuggestionTool,
defaultBlockWidgets,
defaultFormatWidgets,
defaultMarkdownPlugins,
defaultSuggestionWidgets,
Grid,
Heading,
InlineImageBlock,
InlineCode,
Link,
OLItem,
Paragraph,
scaffold,
Text,
ULItem,
createTOCTool
} from "minditor";
const root= document.getElementById('root')!
const types = {
Paragraph,
Text,
Heading,
OLItem,
ULItem,
InlineCode,
Code,
Link,
Grid,
Image: InlineImageBlock
}
const plugins = [
...defaultMarkdownPlugins,
createBlockTool(defaultBlockWidgets),
createRangeTool( defaultFormatWidgets ),
createSuggestionTool(defaultSuggestionWidgets),
createTOCTool()
]
const result = scaffold(root, {data: jsonData, types, plugins}, { debug: true })
result.render()
手机预览