Hi, agian me with probably noob question. Well I “configured” my workplace and succesfully somehow added editor with markdown preview but now I stuck trying to add another plugin. My code looks like this
import { EditorView } from 'prosemirror-view';
import { EditorState } from 'prosemirror-state';
import {
schema,
defaultMarkdownParser,
defaultMarkdownSerializer
} from 'prosemirror-markdown';
import { exampleSetup } from 'prosemirror-example-setup';
class MarkdownView {
constructor(target, content) {
this.textarea = target.appendChild(document.createElement('textarea'));
if (content == undefined) {
this.textarea.value = '';
} else {
this.textarea.value = content;
}
}
get content() {
return this.textarea.value;
}
focus() {
this.textarea.focus();
}
destroy() {
this.textarea.remove();
}
}
class ProseMirrorView {
constructor(target, content) {
this.view = new EditorView(target, {
state: EditorState.create({
doc: defaultMarkdownParser.parse(content),
plugins: exampleSetup({ schema })
})
});
}
get content() {
return defaultMarkdownSerializer.serialize(this.view.state.doc);
}
focus() {
this.view.focus();
}
destroy() {
this.view.destroy();
}
}
let place = document.querySelector('#editor');
let view = new MarkdownView(place, document.querySelector('#content').value);
document.querySelectorAll('input[type=radio]').forEach(button => {
button.addEventListener('change', () => {
if (!button.checked) return;
let View = button.value == 'markdown' ? MarkdownView : ProseMirrorView;
if (view instanceof View) return;
let content = view.content;
view.destroy();
view = new View(place, content);
view.focus();
});
});
I tried to add table plugin into “exampleSetup plugins” but got only errors. Didn’t find anything about extending editor to new functionality with those all npm package.