You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-02 22:49:09 +02:00
27 lines
763 B
TypeScript
27 lines
763 B
TypeScript
|
|
import { DOMParser as ProseMirrorDomParser } from 'prosemirror-model';
|
||
|
|
import { EditorView } from 'prosemirror-view';
|
||
|
|
import schema from '../schema';
|
||
|
|
import { EditorState, Plugin } from 'prosemirror-state';
|
||
|
|
|
||
|
|
type PluginList = Plugin[]|(Plugin|Plugin[])[];
|
||
|
|
|
||
|
|
interface Options {
|
||
|
|
parent?: HTMLElement;
|
||
|
|
html: string;
|
||
|
|
plugins?: PluginList;
|
||
|
|
}
|
||
|
|
|
||
|
|
const createTestEditor = ({ html, parent = null, plugins = [] }: Options) => {
|
||
|
|
const htmlDocument = new DOMParser().parseFromString(html, 'text/html');
|
||
|
|
const proseMirrorDocument = ProseMirrorDomParser.fromSchema(schema).parse(htmlDocument);
|
||
|
|
return new EditorView(parent, {
|
||
|
|
state: EditorState.create({
|
||
|
|
doc: proseMirrorDocument,
|
||
|
|
plugins: plugins.flat(),
|
||
|
|
schema,
|
||
|
|
}),
|
||
|
|
});
|
||
|
|
};
|
||
|
|
|
||
|
|
export default createTestEditor;
|