Class ProseMirrorConverter

java.lang.Object
net.carcdr.yprosemirror.ProseMirrorConverter

public final class ProseMirrorConverter extends Object
Converts ProseMirror documents to Y-CRDT structures.

This class provides utilities for converting ProseMirror nodes, fragments, and documents into their Y-CRDT XML equivalents (YXmlFragment, YXmlElement, YXmlText).

Mapping Strategy:

  • ProseMirror Node → YXmlElement (node type becomes XML tag)
  • ProseMirror Fragment → YXmlFragment (container for nodes)
  • Text content → YXmlText (with marks as formatting attributes)
  • Node attributes → XML element attributes

Usage Example:


 // Convert a ProseMirror document to Y-CRDT
 YDoc ydoc = ProseMirrorConverter.prosemirrorToYDoc(pmNode, schema);

 // Or convert to an existing YXmlFragment
 try (YDoc ydoc = new YDoc();
      YXmlFragment fragment = ydoc.getXmlFragment("prosemirror")) {
     ProseMirrorConverter.nodeToYXml(pmNode, fragment, schema);
 }
 
Since:
0.1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    fragmentToYXml(com.atlassian.prosemirror.model.Fragment pmFragment, YXmlFragment yFragment, com.atlassian.prosemirror.model.Schema schema)
    Converts a ProseMirror Fragment to a YXmlFragment.
    static void
    nodeToYXml(com.atlassian.prosemirror.model.Node node, YXmlFragment fragment, com.atlassian.prosemirror.model.Schema schema)
    Converts a ProseMirror Node to a YXmlFragment.
    static YDoc
    prosemirrorToYDoc(com.atlassian.prosemirror.model.Node doc, com.atlassian.prosemirror.model.Schema schema)
    Converts a ProseMirror document to a new YDoc.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • nodeToYXml

      public static void nodeToYXml(com.atlassian.prosemirror.model.Node node, YXmlFragment fragment, com.atlassian.prosemirror.model.Schema schema)
      Converts a ProseMirror Node to a YXmlFragment.

      This method traverses the ProseMirror node tree and creates corresponding YXmlElement and YXmlText nodes in the target fragment. The conversion preserves:

      • Node hierarchy and structure
      • Node types (as XML tags)
      • Node attributes (as XML attributes)
      • Text content and formatting (as YXmlText with attributes)
      Parameters:
      node - the ProseMirror node to convert
      fragment - the target YXmlFragment to populate
      schema - the ProseMirror schema for validation
      Throws:
      IllegalArgumentException - if node or fragment is null
      IllegalStateException - if the fragment is closed
    • fragmentToYXml

      public static void fragmentToYXml(com.atlassian.prosemirror.model.Fragment pmFragment, YXmlFragment yFragment, com.atlassian.prosemirror.model.Schema schema)
      Converts a ProseMirror Fragment to a YXmlFragment.
      Parameters:
      pmFragment - the ProseMirror fragment to convert
      yFragment - the target YXmlFragment to populate
      schema - the ProseMirror schema for validation
      Throws:
      IllegalArgumentException - if any parameter is null
      IllegalStateException - if the fragment is closed
    • prosemirrorToYDoc

      public static YDoc prosemirrorToYDoc(com.atlassian.prosemirror.model.Node doc, com.atlassian.prosemirror.model.Schema schema)
      Converts a ProseMirror document to a new YDoc.

      This is a convenience method that creates a new YDoc and populates it with the converted ProseMirror document. The document is stored in a YXmlFragment named "prosemirror".

      Parameters:
      doc - the ProseMirror document to convert
      schema - the ProseMirror schema
      Returns:
      a new YDoc containing the converted document
      Throws:
      IllegalArgumentException - if doc or schema is null