htmlSnippet() parses small HTML fragments into Satori-compatible React nodes. It works around Satori’s inline layout limitation by splitting text into per-word flex items with flex-wrap and gap.
Import
Function Signature
Parameters
HTML fragment or plain text. When no HTML tags are detected, the string is returned unchanged (plain mode).
Returns
- Plain mode — returns the original string.
- HTML mode — returns a flex container with per-word
<span>children, preserving inline styles from allowed tags.
Allowed Tags
Only these inline tags are permitted:
Tags like
div, p, a, img, script, and event handlers (onclick, etc.) are rejected. Invalid fragments fall back to plain text with a development warning.
Examples
Migration from objectToStyle
objectToStyle has been removed from @ogify/core. Use htmlSnippet for inline styled text, or write inline style attributes / clsx for layout: