Searching Puzzle Pieces

Type to search Puzzle Pieces.

Rich Text

Renders a stored rich text document — the JSON tree Rich Text Editor emits — as semantic HTML with the shared typography classes. A zero-dependency tree walker built on createTextNode, so stored content can never inject markup.

Installation

Copy the piece into your app — no npm packages required:

puzzle add piece rich-text

Usage

import RichText from '@/components/ui/RichText.pzl';
<RichText doc={ article.body } />

Content renders client-side (the walker runs after mount), so it appears after takeover on prerendered pages rather than in the baked markup.

Data format

The tree is a superset of Shopify's rich text metafield format — see the Rich Text Editor page for the full node reference. The example above renders this document:

{
  "type": "root",
  "children": [
    {
      "type": "heading",
      "level": 2,
      "children": [
        {
          "type": "text",
          "value": "Care instructions"
        }
      ]
    },
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "Machine wash "
        },
        {
          "type": "text",
          "value": "cold",
          "bold": true
        },
        {
          "type": "text",
          "value": " with like colors. See the "
        },
        {
          "type": "link",
          "url": "https://example.com",
          "children": [
            {
              "type": "text",
              "value": "full guide"
            }
          ]
        },
        {
          "type": "text",
          "value": "."
        }
      ]
    },
    {
      "type": "list",
      "listType": "unordered",
      "children": [
        {
          "type": "list-item",
          "children": [
            {
              "type": "text",
              "value": "Do not bleach"
            }
          ]
        },
        {
          "type": "list-item",
          "children": [
            {
              "type": "text",
              "value": "Tumble dry low"
            }
          ]
        }
      ]
    },
    {
      "type": "blockquote",
      "children": [
        {
          "type": "paragraph",
          "children": [
            {
              "type": "text",
              "value": "Lasts twice as long when you follow the label.",
              "italic": true
            }
          ]
        }
      ]
    }
  ]
}