The prosemirror-markdown
package defines a ProseMirror schema that can express exactly the things that can be expressed in Markdown. It also comes with a parser and serializer that convert documents in this schema to and from Markdown text.
To abstract the actual editor, we first create a simple interface around a textarea:
class MarkdownView {
constructor(target, content) {
this.textarea = target.appendChild(document.createElement("textarea"))
this.textarea.value = content
}
get content() { return this.textarea.value }
focus() { this.textarea.focus() }
destroy() { this.textarea.remove() }
}