mirror of https://github.com/fantasticit/think.git
client: fix markdown reference extensions
parent
c5812888f0
commit
57ac872948
|
@ -1,4 +1,4 @@
|
|||
import { Extension } from '@tiptap/core';
|
||||
import { Editor as CoreEditor, Extension } from '@tiptap/core';
|
||||
import { safeJSONParse } from 'helpers/json';
|
||||
import { toggleMark } from 'prosemirror-commands';
|
||||
import { DOMParser, Fragment, Node, Schema } from 'prosemirror-model';
|
||||
|
@ -53,7 +53,13 @@ interface IPasteOptions {
|
|||
*
|
||||
* 将 html 转换为 prosemirror
|
||||
*/
|
||||
htmlToProsemirror: (arg: { schema: Schema; html: string; needTitle: boolean; defaultTitle?: string }) => Node;
|
||||
htmlToProsemirror: (arg: {
|
||||
editor: CoreEditor;
|
||||
schema: Schema;
|
||||
html: string;
|
||||
needTitle: boolean;
|
||||
defaultTitle?: string;
|
||||
}) => Node;
|
||||
|
||||
/**
|
||||
* 将 markdown 转换为 html
|
||||
|
@ -63,7 +69,7 @@ interface IPasteOptions {
|
|||
/**
|
||||
* 将 markdown 转换为 prosemirror 节点
|
||||
*/
|
||||
markdownToProsemirror: (arg: { schema: Schema; content: string; needTitle: boolean }) => Node;
|
||||
markdownToProsemirror: (arg: { editor: CoreEditor; schema: Schema; content: string; needTitle: boolean }) => Node;
|
||||
|
||||
/**
|
||||
* 将 prosemirror 转换为 markdown
|
||||
|
@ -119,12 +125,6 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
console.groupEnd();
|
||||
});
|
||||
|
||||
if (isInTitle(view.state)) {
|
||||
if (text.length) {
|
||||
return insertText(view, text);
|
||||
}
|
||||
}
|
||||
|
||||
// 直接复制节点
|
||||
if (node) {
|
||||
const json = safeJSONParse(node);
|
||||
|
@ -157,6 +157,7 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
// TODO:各家 office 套件标准不一样,是否需要做成用户自行选择粘贴 html 或者 图片?
|
||||
if (html?.includes('urn:schemas-microsoft-com:office') || html?.includes('</table>')) {
|
||||
const doc = htmlToProsemirror({
|
||||
editor,
|
||||
schema: editor.schema,
|
||||
html,
|
||||
needTitle: hasTitleExtension && !hasTitle,
|
||||
|
@ -221,9 +222,11 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
|
||||
// 处理 markdown
|
||||
if (markdownText || isMarkdown(text)) {
|
||||
console.log(text);
|
||||
event.preventDefault();
|
||||
const schema = view.props.state.schema;
|
||||
const doc = markdownToProsemirror({
|
||||
editor,
|
||||
schema,
|
||||
content: normalizeMarkdown(markdownText || text),
|
||||
needTitle: hasTitleExtension && !hasTitle,
|
||||
|
@ -239,6 +242,12 @@ export const Paste = Extension.create<IPasteOptions>({
|
|||
return true;
|
||||
}
|
||||
|
||||
if (isInTitle(view.state)) {
|
||||
if (text.length) {
|
||||
return insertText(view, text);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
handleDrop: (view, event: any) => {
|
||||
|
|
Loading…
Reference in New Issue