Parsing DOM comment nodes

Hello! Maybe a strange use case, but I am considering adding DOM comment nodes to my documents. My idea is to parse comment nodes as-is and to render them as normal DOM nodes in the editor, then later serializing them as comment nodes again.

The issue is that I don’t know how to accomplish this using the schema: I can use a TagParseRule, but there’s no CSS selector to target comment nodes, so the tag property doesn’t work. This means that some DOM node types (Comment, and less importantly CDATASection and ProcessingInstruction) seem unparseable with the standard parser.

If this is out of scope for ProseMirror, could I get a pointer on how to implement this? A custom DOMParser with a new type of rule, maybe?

In any case, thanks a lot for ProseMirror, I appreciate your work!

Indeed, DOMParser just ignores comment nodes entirely. One solution would be to pre-process the HTML text (or the DOM) and replace comments with some element, so that you can target that with a parse rule.

1 Like

Good idea, thanks for the input! I’ll try and post back here once I pursued that - maybe it’s useful for someone else.

1 Like