I’m trying to convert the JSON output back into HTML using Node. Based on what I read, I tried the following:
- create a new node by passing it the JSON and matching schema (saved in a separate file)
- run the node content through DOMSerializer (passing it a document object as an option)
What I have so far:
const {schema} = require("./schema")
const {Node, DOMSerializer} = require("prosemirror-model")
const jsdom = require("jsdom").JSDOM;
let dom = new jsdom('<!DOCTYPE html><div id="content"></div>')
let doc = dom.window.document
let content = {"doc":{"type":"doc","content":[{"type":"paragraph","attrs":{"align":"left"},"content":[{"type":"text","text":"My sample text"}]}]},"selection":{"type":"text","anchor":16,"head":16}}
let contentNode = Node.fromJSON(schema, content.doc)
DOMSerializer
.fromSchema(schema)
.serializeFragment(contentNode.content, {"document": doc })
The code is failing at the Serializer step. As I am a new user, any pointers as to what I could be doing wrong would be welcome.