DeltaHtml converts Quill (Slab) Delta operations into safe HTML on the server.
Installation
Add to mix.exs:
def deps do
[
{:delta_html, "~> 0.5"}
]
endBasic Usage
DeltaHtml.to_html([%{"insert" => "Hello\n"}])
# => "<p>Hello</p>"You can pass:
- a list of ops,
- a
%{"ops" => [...]}map, - or a JSON-encoded Delta document.
Typical App Workflow (Quill + DeltaHtml)
Use DeltaHtml as a rendering layer while keeping Delta as your stored format:
- User edits rich text in Quill on the frontend.
- Frontend sends Quill Delta JSON to backend.
- Backend stores Delta JSON (not pre-rendered HTML) in database.
- On next edit page load, backend sends Delta back and Quill rehydrates editor state.
- For display surfaces (web UI, email templates, exports), backend renders Delta to HTML with
DeltaHtml.to_html/2.
This pattern avoids dual-source drift (Delta + stale HTML) and keeps edit fidelity for future user changes.
Common Options
DeltaHtml.to_html(delta, preserve_whitespace: true)
DeltaHtml.to_html(delta, quill_css: true)
DeltaHtml.to_html(delta, link_sanitization: :strict)preserve_whitespace: true: wraps output withwhite-space: pre-wrap.quill_css: true: emits Quill-style classes for block attributes.link_sanitization: :strict: onlyhttp|https|mailto; drops invalid links.
Recommended Defaults
- Web/email rendering with predictable output:
use default options (
quill_css: false,link_sanitization: :quill). - Security-sensitive contexts:
consider
link_sanitization: :strict. - Reusing Quill theme styles:
set
quill_css: true.