import { sanitizeHTML } from "../../markdown/markdown-parser";
import { DOMSerializer } from "prosemirror-model";
import { hasImageNode } from "../prosemirror-adapter/plugins/image/node";
/**
 * @private
 */
export class HTMLConverter {
    constructor(plugins) {
        this.parseAsHTML = (text) => {
            return sanitizeHTML(text, this.customNodes);
        };
        this.serialize = (view) => {
            if (view.dom.textContent.trim() === '' &&
                !hasImageNode(view.state.doc)) {
                return '';
            }
            const div = document.createElement('div');
            div.append(DOMSerializer.fromSchema(view.state.schema).serializeFragment(view.state.doc.content));
            return div.innerHTML;
        };
        this.customNodes = plugins;
    }
}
