Rendering rich text in another framework
@eldrajs/vue is one wrapper over @eldrajs/rich-text. A React, Svelte or Solid wrapper is welcome, and this is the contract it has to satisfy so that a document renders the same wherever it lands. If you write one, open a pull request — it lands as @eldrajs/<framework> in this repository. Theme bindings follow the same core-first rule: see docs/theme-reference.md for how @eldrajs/theme-vue wraps the framework-free @eldrajs/theme-core, and what a React theme binding would need to satisfy the same way.
What the core gives you
RichTextDocument,RichTextNode,RichTextMark— the shape. A document is a node of typedoc; atextnode hastextand optionalmarks; every other node may haveattrsandcontent.resolveOverride(override, defaultComponent)— the override semantics. Given the consumer's override for a type and your default component, it returns{ is, class?, style? }ornullfor "children only". Do not reimplement the rules; use it.safeHref,safeImageSrc,safeCssColor,isTrustedEmbedSource— the safety rules. Use them in exactly the places the Vue defaults do: the link'shref, the image'ssrc,textStyle's colour, the embed'ssrc.normalizeEmbedInput,EMBED_SOURCE_HOSTS— embeds.extractTipTapText,renderTipTapText— plain text.toHtml— if your framework can take an HTML string, you may not need a wrapper at all.
What a wrapper must do
- Walk the tree the way
RenderNodedoes: atextnode renders its text wrapped in its marks withmarks[0]outermost; any other node resolves an override or default for itstypeand renderscontentinside it; an unknown type with no override renders its children with no wrapper. - Pass
nodeandattrsto a node component,markandattrsto a mark component, and the rendered children as the component's children. - Implement the same defaults with the same output — the list in rich-text.md. The Vue components under
packages/vue/src/rich-text/defaults/are the reference; each is a few lines. - Apply the safety rules through the core helpers, not your own.
- Split tables into
<thead>for the leading rows made only oftableHeadercells and<tbody>for the rest. - Embeds: iframe mode renders the iframe with
loading="lazy"andreferrerpolicy="strict-origin-when-cross-origin", sized fromwidth/height, and may accept posted height messages only fromhttps://embed.reddit.com; script mode loads the provider script once per page and calls its hydrate hook, or renders a link to the original. - Warn once per unknown node type in development, and never in production.
What a wrapper must not do
- Import anything from
@eldrajs/vueor from the private UI library. - Emit consumer-supplied HTML verbatim, anywhere.
- Add a dependency for animation, styling or icons. The Vue wrapper has none; a
revealdirective is looked up from the host app if it registered one.
Tests to port
packages/vue/src/rich-text/__tests__/RichText.spec.ts is the behavioural spec: defaults, each override kind, null, unknown nodes, tables, embeds, and the safety cases (a javascript: href, a javascript: image, an embed from an unknown host). Port it; a wrapper is done when the same assertions pass.