anatolykoptev

ox payload editorial

by anatolykoptev
Rich text & editors
v3
v4
^3.93.0 || ^4.0.0-beta.12
Apache-2.0

Overview

Summary generated from the README

Adds editorial Lexical blocks to a Payload collection and an API-only markdown field that reads and writes the whole body using ::: directives. Markdown is only returned when re-importing it reproduces the stored content exactly; otherwise writes are refused. Server components render post bodies from CSS tokens. Requires Payload 3 or 4, Lexical, React 19 and an upload collection with the slug media.

Features

  • Markdown companion field that reads and writes the full rich-text body, filled for Payload MCP requests
  • Block directives such as finding, note, aside, steps, pull quote, stats, table, bars, compare and delta
  • Round-trip check that returns null markdown and refuses writes when content would be lost
  • Validation rules, e.g. a pull quote must repeat a sentence of the article and stats must appear in the body
  • Server components and stylesheet themed through CSS tokens, with contents, FAQ data and related reads
  • Adds a related posts relationship and a content field to configured collections

Use cases

  • Let AI agents write structured articles in markdown without damaging rich Lexical content
  • Render magazine-style post bodies styled by your own design tokens
  • Add editorial callouts, stat bands and data tables to a blog collection

From the author

Editorial blocks for Payload CMS 3 and 4: write markdown with ::: directives, store rich Lexical blocks, read them back losslessly, and render post bodies styled by your own tokens.

Installation

npm i ox-payload-editorial

0

Stars

0

Forks

2

Open Issues

2 days ago

Last Updated

0

Weekly Downloads

v

npm Version

Dependencies

GitHub stars

Trends appear once the first and last snapshots are 7 days apart. Collecting since Nov 29 — 7 daily snapshots so far.

npm weekly downloads

Trends appear after 7 days of data. Daily snapshots have not started yet.

Each point is npm's rolling 7-day download count.

Health Score

25/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1481433083-root.svg)](https://payloaddirectory.dev/plugins/1481433083-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1481433083-root"><img src="https://payloaddirectory.dev/badge/1481433083-root.svg" alt="Payload Directory"></a>
Updated Dec 3, 2026Created Dec 2, 2026

README

ox-payload-editorial

npm CI License: Apache-2.0

Editorial blocks for Payload CMS 3 and 4. Agents and authors write markdown with ::: directives; the plugin turns it into rich Lexical blocks and back without losing content, and the components render them as magazine-style post bodies styled by your own tokens.

A rendered travel feature: a stat band over a drop-cap lead paragraph

Why

An agent that writes into a CMS should not have to learn a block editor, and a block editor should not lose content when an agent touches it. This package gives a Payload collection one markdown field that reads and writes the whole body, a set of blocks with rules that keep the prose honest (a pull quote can only repeat a sentence of the article, a stat must be findable in the body), and server components that draw it all from --ed-* CSS tokens, with no site styling inside.

Status: pre-1.0, the API can still change in a minor release. Releases are published from this repository's CI to npm with provenance.

Install

pnpm add ox-payload-editorial

Peers: payload and @payloadcms/richtext-lexical ^3.93.0 || ^4.0.0-beta.12, react and react-dom ^19.3. next is optional. Node ^22.23.5 || ^24.22.3 || >=26.13.1 (Payload 4 itself needs ^24.22.3 || >=26.13.1), ESM only. The body's figures point at an upload collection with the slug media, which must exist.

Compatibility

Payload 3 (stable) and Payload 4 (beta), both tested in CI: the whole suite, including the real-Payload round trip, runs against 3.94.2 and 4.0.0-beta.12. Payload 4 is not the default: a site on 3 installs and behaves exactly as before. Payload 4's converter escapes literal [x] and keeps spaces inside inline code, so a few bodies that Payload 3 refuses to offer as markdown are offered on 4 (they round-trip there); the read-back comparison decides, not a list.

Quick start

// payload.config.ts
import { editorialPlugin } from 'ox-payload-editorial/plugin'

export default buildConfig({
  collections: [Posts, Media], // Media is an upload collection with the slug "media"
  plugins: [editorialPlugin({ collections: { posts: { related: 'relatedPosts' } } })],
})

posts now has a content rich-text field with the editorial blocks, an API-only markdown companion and a relatedPosts relationship. Render the body in a server component:

import { PostBody, postOutline } from 'ox-payload-editorial/body'
import 'ox-payload-editorial/styles.css'

const outline = postOutline(post.content.root, 'example.com')
<PostBody nodes={outline.nodes} sections={outline.sections} />

A complete config and page are in examples/, with the markdown behind the screenshots on this page. docs/rendering.md covers contents, sources, FAQ data, figures and related reads.

What an agent writes

A directive is :::name, a body and a closing :::. Plain markdown is styled by its shape: the first paragraph becomes the lead, ## Heading a section opener, a list of bold lead-ins a timeline, ## FAQ an FAQ with structured data.

DirectiveRenders as
:::findinga raised panel for the answer or key takeaways
:::notea muted note between two rules: method, caveat
:::asidea side note in the margin beside the paragraph it follows
:::stepsa numbered sequence of 2 to 5 named steps
:::pulla large pull quote, which must repeat a sentence of the article word for word
:::statsa strip of 1 to 4 key figures, each of which must appear in the body; first in the body it can be drawn as a hero band
:::tablea captioned table
:::barsa table drawn as proportional bars
:::comparea table with large figures in two or three columns
:::deltabefore and after per row, as a dot plot with the full table under it

Code fences, tables and ![alt](media:ID "Caption") figures work too. Every rule, with the error each break returns, is in SYNTAX.md, which ships in the package.

Callouts: an aside and a numbered steps block

Data blocks: a captioned table, a comparison with large figures, and bars

Lossless round trip

Markdown cannot say everything a Lexical document can: an internal link, underline, a block of your own. A converter that ignores this silently deletes content on the next save. This package does not rewrite anything markdown cannot carry exactly.

Before it returns markdown, it exports the stored body, imports that markdown again with the same code a write uses, and compares the result with what is stored, value by value. If they are identical, you get the markdown. If anything differs, markdown is null and a markdown write to that document is refused with an error telling you to edit content instead. It fails closed: a field the comparison has never heard of counts as a difference. Only generated ids and node version numbers are ignored.

The markdown field is filled for Payload MCP requests and is never stored. The mechanism, step by step, is in docs/round-trip.md.

Theming

Import styles.css and map your own tokens once, on any element above the post:

.post {
  --ed-ink: var(--site-ink);
  --ed-canvas: var(--site-paper);
  --ed-hairline: var(--site-rule);
  --ed-display: var(--site-font-sans);
  --ed-text: var(--site-font-serif);
  --ed-measure: 34em;
}

The defaults are neutral ink on white with system fonts, at zero specificity, so any mapping wins. Every class is ed- prefixed and nothing is scoped to a site class. The full token list is in docs/tokens.md.

Documentation

docs/INDEX.md lists every document: the round-trip guard, tokens, rendering, the generated MCP instructions, and the migration helper unpadLegacyTables for bodies imported by an older importer.

Development

pnpm install
pnpm test -- test/postRules.spec.ts   # scoped tests
make preflight                         # lint, typecheck, test, build, export check: what CI runs

See CONTRIBUTING.md. Licensed under Apache-2.0.

Similar plugins