react-email-studio-convert
v4.0.0
Published
Convert HTML ↔ React Email Studio email_document JSON (no React editor required).
Maintainers
Readme
react-email-studio-convert
Latest: 4.0.0 — Aligned with [email protected]. See CHANGELOG.md.
4.0.0 — Version alignment with studio 7.0.0 (controlled options, palette, presets, custom widgets; no convert API changes).
3.1.4 — Aligned with [email protected].
3.1.0 — Universal export sanitization and Outlook VML backgrounds with [email protected].
Convert between HTML and the React Email Studio email_document JSON format — without the React editor UI.
Use this package in Node scripts, APIs, or CI when you need to:
- Import pasted or exported HTML into the studio (
loadJson) - Export saved designs to send-ready HTML (including optional dark-mode CSS)
Install
npm install react-email-studio-convertNo React required. Node.js 18+ is supported (uses happy-dom for DOMParser / HTML normalization when globals are missing).
Monorepo workspace:
"react-email-studio-convert": "workspace:*"Node.js
ESM
import {
htmlToStudioDocument,
studioDocumentToHtml,
} from "react-email-studio-convert";
const doc = htmlToStudioDocument("<p>Hello</p>");
const html = studioDocumentToHtml(doc);CommonJS
const {
htmlToStudioDocument,
studioDocumentToHtml,
} = require("react-email-studio-convert");
const doc = htmlToStudioDocument("<!DOCTYPE html><html><body><p>Hi</p></body></html>");
console.log(studioDocumentToHtml(doc).includes("Hi")); // trueAPI
| Function | Description |
|----------|-------------|
| htmlToStudioDocument(html) | HTML → email_document object (or null if empty) |
| htmlToStudioJson(html, pretty?) | HTML → JSON string |
| studioDocumentToHtml(document, opts?) | Document or JSON string → full HTML email |
| normalizeStudioDocument(input) | Canonical email_document object |
| parseStudioDocument(input) | Coerce legacy / partial JSON for the editor |
| studioDocumentToRows(input) | Document → editor row model |
| studioRowsToDocument(rows, settings) | Editor rows → email_document |
Low-level exports (jsonToHtml, htmlToJson, blocksFromImportHtml, makeContentBlock, resolveBlockProps, socialBarTableHtml, …) match react-email-studio / react-email-studio/convert for advanced use.
Supported blocks (export / structured import)
heading, text, html, image, file, button, link, divider, spacer, social (inline table icons), menu, table, layout.
Legacy timer, video, countdown, and videoLink blocks are skipped on import (DEPRECATED_BLOCK_TYPES).
Dark mode
When settings.emailDarkModeEnabled is true (default in new designs), studioDocumentToHtml includes color-scheme meta tags and dark-theme CSS. Override colors via settings.emailDarkPageBg, emailDarkContentBg, etc. (see main package docs).
Example
import {
htmlToStudioDocument,
studioDocumentToHtml,
makeContentBlock,
resolveBlockProps,
} from "react-email-studio-convert";
const doc = htmlToStudioDocument("<h1>Hi</h1><p>Body</p>");
// Pass to ReactEmailEditor loadJson(doc) or save JSON
const html = studioDocumentToHtml(doc);
// Full <!DOCTYPE html>… document for your ESP
// Build a document block in Node (same presets as editor blockPresets)
const socialBlock = makeContentBlock("social", {
social: {
networks: ["linkedin"],
socialUrls: { linkedin: "https://linkedin.com/company/acme" },
},
});Format
The studio document is type: "email_document" with settings and rows[] (each row has columns[].blocks[]). See react-email-studio docs for the full schema.
Related
- react-email-studio — visual editor component
