Model document with DocumentFragment instead of JSON

Hello marijn!

I’ve been studying the design of contenteditable libraries and I’ve noticed they all struggle with HTML validation because they store their document model as “DOM-like” JS nodes. Creating a schema that adheres to HTML5’s content category specs and properly implementing parseDOM⁠ is difficult.

This has me thinking, would it be good to model the document using a DocumentFragment? A DOMParser implementation would handle most of the validation. A schema could be enforced by whitelisting certain elements and attributes. toDOM would become obsolete and parseDOM could transform invalid elements and attributes into valid ones.

I’d love your thoughts on potential downsides besides slow serialization and deserialization. Am I wrong about schema enforcement? Would the view be difficult to hook up? Would transactions be difficult to implement? I’m really curious what the pros and cons are.

Thanks for the de-facto contenteditable library and great community support!

A DocumentFragment is a list of DOM nodes. It is not clear to me what modeling the editor document as such a thing would mean or what advantages it would have.