Expand description
Custom render rules and segmented output — the extensibility core shared by both HTML renderers.
Callers register per-node rules. Two tiers:
- Declarative rules (tag, attributes, text, content slot) compile to
NodeRule/MarkRulehere and render natively, inside the document transaction, at full speed. This covers the tiptap-phprenderHTMLshape: markup as data. - Callback rules defer to the caller. Rendering never runs app code
while the document is locked — the renderer emits
Segment::Deferredentries carrying the node’s type, attributes (as JSON), and its already-rendered children, and the caller fills them in after the render returns. (In the Ruby gem, that caller is the app’s block, run once the transaction has closed and the GVL is held again.)
Rules arrive as one JSON document (see parse), so the same format
serves any binding or caller.
Structs§
- Emitter
- Builds segmented output. Renderers append markup through this instead of a
bare
String; frames capture sub-output (a deferred node’s children, or a “did this render anything?” probe) without string sentinels. - Mark
Rule - A custom mark (ProseMirror only): a wrapping tag with attributes read from the mark’s own value map.
- Rules
- Type
Info - What a document walk observed about one node type — the facts behind
Y::Lexical#node_types/Y::ProseMirror#node_types, the discovery aid for writing rules against a real document.
Enums§
- Attr
Part - A piece of an attribute value or text template: a literal, or a reference to one of the node’s stored attributes.
- Content
- What goes inside a custom node’s element.
- Flattened
- What flattening produced. Both variants are normal outcomes —
Deferredmeans callback nodes are present and need splicing — so this is an enum rather than aResult. - Node
Rule - One node rule: markup as data, or a deferral to the caller.
- Segment
- One piece of renderer output.
Htmlis finished markup;Deferredis a callback node whose markup the caller supplies after the render, carrying everything needed to produce it. Content nests, so callback nodes inside callback nodes resolve depth-first.child_typeslists the node’s element/block children by type, in document order — structural facts a callback can’t recover fromattrsor the rendered content (an image count, whether a list item holds a nested list).
Functions§
- any_
attr_ string - A stored attribute as a string: strings pass through; numbers print JS-style; bools as true/false. Anything else is None.
- flatten
- Join the segments when every one is finished markup, so the common no-callback path stays a single string and the splicing layer can be skipped; hand the segments back untouched when callback nodes are present.
- resolve_
parts - Resolve a lit/ref template against a node’s attributes.
None(attribute or text skipped) when the resolved value is empty — matching how the built-in renderers omit absent attributes. - type_
map_ json - Serialize the observations, annotating each type with what already
handles it (
"rule","builtin", or null — the ones a rule author needs to cover). - xml_
attrs_ json - A node’s stored attributes as a JSON object, for callback rules. Keys as
stored (
__typeand friends keep their prefix); values via yrs’s own JSON encoding. - xml_
ref_ attr - An attribute reference on a node: rules say
:kind; Lexical stores its own props as__kind— try the raw name first, then prefixed. (ProseMirror stores attrs bare, so the fallback never fires there.)
Type Aliases§
- TypeMap
- Per-type observations, ordered for stable output.