prosemirror-markdown/alpha/ProseMirrorView.ts

29 lines
797 B
TypeScript

import { EditorView } from 'prosemirror-view';
import { EditorState } from 'prosemirror-state';
import { schema, defaultMarkdownParser, defaultMarkdownSerializer } from 'prosemirror-markdown';
import { exampleSetup } from 'prosemirror-example-setup';
export class ProseMirrorView {
view: any;
constructor(target: any, content: string) {
let tmpDoc = defaultMarkdownParser.parse(content);
let tmpDoc1 = tmpDoc === null ? undefined : tmpDoc;
this.view = new EditorView(target, {
state: EditorState.create({
doc: tmpDoc1,
plugins: exampleSetup({ schema })
})
});
}
get content(): string {
return defaultMarkdownSerializer.serialize(this.view.state.doc);
}
focus() {
this.view.focus();
}
destroy() {
this.view.destroy();
}
}