diff --git a/server/models/Document.ts b/server/models/Document.ts index 7df7966966..5a804d6c24 100644 --- a/server/models/Document.ts +++ b/server/models/Document.ts @@ -759,21 +759,28 @@ class Document extends ParanoidModel { }; /** - * Returns the document as plain HTML. This is a lossy conversion and should - * only be used for export. This method uses the collaborative state if - * available, otherwise it falls back to Markdown -> HTML. + * Returns the document as a Prosemirror Node. This method uses the + * collaborative state if available, otherwise it falls back to Markdown->HTML. * - * @returns The document content as a HTML string + * @returns The document content as a Prosemirror Node */ - toHTML = () => { - let node; + toProsemirror = () => { if (this.state) { const ydoc = new Y.Doc(); Y.applyUpdate(ydoc, this.state); - node = Node.fromJSON(schema, yDocToProsemirrorJSON(ydoc, "default")); - } else { - node = parser.parse(this.text); + return Node.fromJSON(schema, yDocToProsemirrorJSON(ydoc, "default")); } + return parser.parse(this.text); + }; + + /** + * Returns the document as plain HTML. This is a lossy conversion and should + * only be used for export. + * + * @returns The document title and content as a HTML string + */ + toHTML = () => { + const node = this.toProsemirror(); const dom = new JSDOM( `