UNPKG

@rtdui/editor

Version:

React rich text editor based on tiptap

50 lines (46 loc) 1.87 kB
'use client'; 'use strict'; var core = require('@tiptap/core'); var state = require('@tiptap/pm/state'); var MarkdownIt = require('markdown-it'); var model = require('@tiptap/pm/model'); var markdownItKatex = require('./markdown-it-katex.cjs'); const MarkdownPaste = core.Extension.create({ name: "markdownPaste", addProseMirrorPlugins() { return [ new state.Plugin({ key: new state.PluginKey("markdownPaste"), props: { handlePaste: (view, event) => { if (view.state.selection.$head.parent.type.name !== "paragraph") { return false; } const markdownit = new MarkdownIt({ html: false, // 不允许mardown中有html, 标准的markdown规范是允许的 highlight: (str, lang) => "", // 返回空字符串表示不需要进行语法处理. 在外部由CodeBlockLowlight扩展处理, 只需要使用默认的<pre><code class="language-xxx">包裹即可 linkify: true, // 自动识别超链接 breaks: true // 启用软换行, 即行尾的回车即会创建<br/>. 标准的markdown规范需要在行尾两个空格加一个回车才会创建<br/>. }).use(markdownItKatex); const html = markdownit.render( event.clipboardData?.getData("text") || "" ); const body = core.elementFromString(html); const node = model.DOMParser.fromSchema( this.editor.schema ).parse(body); this.editor.commands.insertContent(node.toJSON()); return true; } // Here is the full list: https://prosemirror.net/docs/ref/#view.EditorProps } }) ]; } }); exports.MarkdownPaste = MarkdownPaste; //# sourceMappingURL=markdownPaste.cjs.map