Skip to main content

Rich text and entity references

VoxRichText is a structured document with a fixed set of node types: paragraphs, headings, strong, emphasis, underline and strikethrough text, ordered and unordered lists, blockquotes, preformatted text, code, line breaks, links and embedded entities. Vox stores, compares and delivers it as a semantic JSON document. HTML is a syntax it can also be written in and delivered as, when a client asks for it. Search indexes the document's visible text.

For the team workflow, see Connect products and variants.

public virtual VoxRichText Description { get; set; } = VoxRichText.Empty;

Create a value with VoxRichText.FromDocument(document), or with VoxRichText.Parse(html). A document is validated and normalized: adjacent text becomes one text node, empty text is left out and each node keeps only the properties of its type, so the same content always makes an equal value. HTML input must be well-formed XML-style HTML. Vox accepts its documented formatting elements and safe link attributes only; unsupported elements, malformed nesting, event/style attributes, and unsafe URL schemes fail validation rather than being silently repaired. Ordinary links use <a>. Entity references use a dedicated empty element:

<vox-entity ref="vox://entity/Product/p123" projection="product-card"></vox-entity>

The URI identifies the entity type and ID. The optional projection attribute selects one of that entity type's entity projections. When it is omitted, Vox uses the reference default. Referenced entities may be missing; the reference remains valid and expansion reports a diagnostic.

The semantic JSON representation uses an entity-reference node with the same entity identity and optional projection hint. HTML and JSON therefore describe a reference, not a copied object. The projected value is resolved only when a consumer asks Vox to expand references.

Use the same projection everywhere​

Rich text references use the same projection contracts as every other consumer. A product card used inside an article is produced by the same IVoxEntityProjectionFactory<Product, ProductCard> that an application can request directly or use for an ordinary relation reference:

public record ProductCard(string Id, string Name, string Url, VoxRichText Teaser);

[VoxEntityProjection("product-card", "1", IsDefaultForReferences = true)]
public class ProductCardProjection
: IVoxEntityProjectionFactory<Product, ProductCard>
{
public Task<ProductCard?> ProjectAsync(
Product product,
IVoxEntityProjectionContext context,
CancellationToken cancellationToken)
{
return Task.FromResult<ProductCard?>(new(
product.Id,
product.Name,
$"/products/{product.Id}",
product.Teaser));
}
}

An entity embedded in rich text is a projection reference, like a VoxProjectionRef<T> in a projection's output (see Entity projections). The output contract may contain nested rich text, and its references are materialized into the same graph. Entity types are rejected in projection output contracts, so the projection cannot accidentally expose every stored property.

API delivery​

Entity, relation, and projection reads accept:

?richTextFormat=Html|Json&referenceDepth=0..8

Json is the default and returns the versioned semantic document with typed nodes such as paragraph, heading, link, and entity-reference. It's compact: camelCase names, no null properties and no empty children except the document's own, so empty rich text is {"version":1,"type":"document","children":[]}. Html returns the canonical HTML string instead, eg for a server-rendered site or an email template:

{
"version": 1,
"type": "document",
"children": [
{ "type": "paragraph", "children": [{ "type": "text", "text": "Pair it with " }] },
{
"type": "entity-reference",
"ref": "vox://entity/Product/p123",
"entityType": "Product",
"entityId": "p123",
"projection": "product-card",
"key": "vox://entity/Product/p123?projection=product-card"
}
]
}

A response adds key to each entity-reference node: the key of the projection it resolves to in the response's _projections or projections, with the entity type's reference default when the node names no projection, eg vox://entity/Product/p123?projection=card. A client looks the embedded projection up by it without assembling the key or following the aliases. A document written to Vox doesn't need it, and Vox ignores it there.

Writes accept either form: a property can be written as the document or as an HTML string, and both store the same value. Excel workbooks hold rich text as HTML, which a person can edit in a cell.

Responses that have no richTextFormat parameter, eg the entity a write returns, history versions, the audit trail and cells, hold rich text as the stored document, without key on its embeds, since they have no _projections.

A document is normalized when it's written, as the same HTML would be: CR LF and CR become LF, and tabs and line breaks in a link's href or title become spaces. Nodes nest at most 16 levels deep, eg a list in a quote in a list; deeper rich text is refused. An embedded entity is a block, so it can't be inside a paragraph, a heading, a link or inline formatting.

Vox Serve delivers rich text in the same JSON form and has no richTextFormat parameter, so a touchpoint renders the document itself, eg an embedded product as its card component, whether it reads Vox core or Vox Serve.

The MCP tools are the exception: they read rich text as HTML unless an agent asks for Json, since HTML is about a third of the tokens of the same document, and they write it as HTML.

Rich text is found in a response by its shape, an object with version, "type": "document" and children. An object of an application's own output that is a valid rich-text document in every way would be formatted like one, eg turned into HTML with richTextFormat=Html.

With a referenceDepth above 0, the response receives a flat _projections object with the referenced projections, and the projections they reference, up to that many levels. Each entry includes the entity type and ID, selected projection and version, and projected value. Keys are the canonical vox://entity/... URI with ?projection=..., so two representations of the same entity can coexist. A reference without a projection hint resolves to the entity type's reference default, and _projectionAliases maps its key without ?projection=... to the key it resolved to. _projectionDiagnostics describes missing targets and references cut off by a limit.

Materialization evaluates each projection once, however often it's referenced, so cycles stay finite, and it has depth, projection-count, and output-size limits. Missing targets, projections of entities the caller can't read and projections that aren't for content delivery produce diagnostics rather than a failed response.

Materialization uses the request's content scope and context selection. A draft or release response therefore projects the corresponding draft/release view of every entity in the graph. For the content endpoint, /api/{entityType}/{id}/content, the published and draft halves are materialized independently. Direct entity projection responses materialize 8 levels by default; ordinary entity and relation responses only when referenceDepth is set. The client's getProjectionGraph, resolveProjectionRef and inlineProjectionRefs read the graph.

Entity embed index​

Vox extracts references when an entity is written and persists them separately from ordinary relations, in the entity embed index. Each row records the scope it's in, eg draft, source entity type and ID, property path, varying context key, target entity type and ID, and optional projection hint. IVoxEntityEmbedIndex reads the embedded entities of a source entity in a scope. Applications that need relationships never have to walk stored documents, and published, draft, and release references cannot leak into one another.

The fields of field sets can use RichText too. Rich text is not filterable, sortable, unique, pattern-constrained, or a string/list-length field. Editor metadata gives it the field type RichText, which selects the rich text editor.