Post by SEBASTIEN PORTRAIT
Coelho - Structured rich text for Phoenix
I’ve just published Coelho, a structured rich text library for Phoenix.
The idea is somewhat inspired by Rails’ Action Text: provide a proper rich text layer between the editor in the browser and the application’s data model.
But instead of storing HTML, Coelho stores the document as a structured JSON tree — the same kind of document model used by ProseMirror.
That gives the application a single source of truth for both the editor and the server:
- define the document schema once in Elixir
- export the schema to ProseMirror
- validate documents before they reach the database
-
store the document directly in a
jsonbcolumn - render it to HTML or extract plain text
- customise rendering without changing the stored document
- use different, restricted schemas for different rich text fields
- validate and cast rich text directly through Ecto
- use it from Phoenix LiveView with an included editor
- support attachments with URLs resolved at render time
One of the things I particularly wanted to avoid is treating HTML as the data model.
When rich text is stored as HTML, the markup becomes part of the persisted data. With a structured document instead, the data remains queryable and migratable, while rendering stays an application-level decision.
Coelho also deliberately keeps the core small: no file storage, image processing or collaborative editing. Those are integration points rather than responsibilities of the document layer.
It’s early, but the core is already in place and tested.
I’d particularly love feedback from people building Phoenix applications that need rich text, especially if you’ve used Action Text or another structured rich text solution before.
HexDocs: coelho.hexdocs.pm/readme.html
Hex.pm: hex.pm/packages/…