Skip to main content

Crate yjs_html_core

Crate yjs_html_core 

Source
Expand description

The custom render rules and segmented output that both HTML renderers share.

Callers register a rule per node. There are two tiers:

  • A declarative rule (tag, attributes, text, content slot) compiles to a NodeRule or MarkRule and renders natively, inside the document transaction, at full speed. This covers the tiptap-php renderHTML shape: markup as data.
  • A callback rule defers to the caller. The renderer never runs application code while the document is locked. It emits Segment::Deferred entries with the node type, the attributes as JSON, and the 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 one format serves every binding and 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.
MarkRule
A custom mark (ProseMirror only): a wrapping tag with attributes read from the mark’s own value map.
Rules
TypeInfo
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§

AttrPart
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 — Deferred means callback nodes are present and need splicing — so this is an enum rather than a Result.
NodeRule
One node rule: markup as data, or a deferral to the caller.
Segment
One piece of renderer output. Html is finished markup; Deferred is 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_types lists the node’s element/block children by type, in document order — structural facts a callback can’t recover from attrs or 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 (__type and 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.