# Rich text (Lexical) — RenderRichText Rendering `richText` fields (the Lexical editor) on the frontend. The plugin ships `RenderRichText` — a thin wrapper over Payload's OFFICIAL converter (`@payloadcms/richtext-lexical/react`). It is the RenderBlocks of rich text: the plugin provides the engine, the project provides the look. > **NEVER write your own Lexical renderer** (a switch on `node.type`, bit flags > `node.format & 1`). It duplicates what Payload already does, misses node > types, drifts with Lexical updates and tempts you into > `dangerouslySetInnerHTML` (XSS) and a hardcoded locale (`.pl`). Use > RenderRichText. ## Basic use (RSC) ```tsx import { RenderRichText } from '@intecion/ipal-kit/rsc' ``` Props: `data` (empty → `null`), `className`, `converters`, `headingIds`, `safeLinks` (default `true`). `data` is the richText field from the document — ALREADY localized (Payload returns the value for the current locale). No per-language keys, no hardcoded `.pl`. ## Your own styles per node (converters) The style stays in the project (Tailwind), the parsing in the plugin. Override the JSX of specific nodes through `converters`: ```tsx import { RenderRichText } from '@intecion/ipal-kit/rsc' import type { JSXConvertersFunction } from '@payloadcms/richtext-lexical/react' const converters: JSXConvertersFunction = ({ defaultConverters }) => ({ ...defaultConverters, heading: ({ node, nodesToJSX }) => { const children = nodesToJSX({ nodes: node.children }) const cls: Record = { h2: 'font-display text-2xl font-semibold mt-10 mb-4', h3: 'font-display text-xl font-semibold mt-7 mb-3', } const Tag = node.tag as 'h1' | 'h2' | 'h3' | 'h4' return {children} }, paragraph: ({ node, nodesToJSX }) => (

{nodesToJSX({ nodes: node.children })}

), }) ``` Spread `defaultConverters` — you override only the nodes you want. The rest (lists, tables, images, links) works through Payload's official handling. **Links are filtered as in `` (`safeHref`).** A custom link with an address outside `http(s)`, `mailto`, `tel`, `sms`, `#`, `/` (e.g. `javascript:`, `data:`) gets `href="#"` — also when it reached the database through an import, a seed or the API, bypassing the panel field. Internal links (`linkType: 'internal'`) are not touched. Turn off (fully trusted content only): ``. ## Table of contents and heading anchors (1.11.1) Long documents (privacy policy, terms) — a table of contents with links to sections. Heading ids in the table and in the content are computed by the same function, so they never drift apart. ```tsx // block config import { buildTableOfContentsField } from '@intecion/ipal-kit' fields: [buildTableOfContentsField(), { name: 'content', type: 'richText' }] // group tableOfContents: show, label // block component (RSC) import { extractHeadings, RenderRichText } from '@intecion/ipal-kit/rsc' import { TableOfContents } from '@intecion/ipal-kit/client' const items = block.tableOfContents?.show ? extractHeadings(block.content) : [] // [{ id, text, level }] {items.length ? : null} ``` - `extractHeadings(content, { levels: ['h2'] })` — headings in text order; id = `toSlug(text)`, repeats `-2`, `-3`, empty headings skipped. Also from the root: `import { extractHeadings, headingText } from '@intecion/ipal-kit'`. - `RenderRichText headingIds` — `true` (h2) or `{ levels, className }`. Your `heading` converter still renders the heading; the plugin adds the `id` (and `className`, e.g. `scroll-mt-*` under a sticky header). - `` — no styles: `