Block Based
GitHub

Rendering HTML

Use renderEmailDocument() to convert a document into clean, production-ready HTML.

Basic Usage

import { renderEmailDocument } from 'block-based';
import type { EmailDocument } from 'block-based';

function exportDoc(doc: EmailDocument) {
  const html = renderEmailDocument(doc);
  // Save to file, render in an iframe, or use anywhere
  return html;
}

Output Characteristics

The generated HTML is designed for broad compatibility:

What Gets Rendered

The renderer processes every part of the document:

Document PartHTML Output
settings.backgroundColorOuter <body> background
settings.contentBackgroundColorInner container background
settings.fontFamily / fontSize / fontWeightApplied to the body wrapper
settings.preheaderTextHidden <div> at the top of the output
Each sectionA <table> row with section-level padding, background, and borders
Each columnA <td> within the section's table row
Each blockBlock-specific HTML (see Block Types)

Using the HTML

The HTML string can be used anywhere — emails, web pages, previews:

// Example: sending as an email
const html = renderEmailDocument(doc);

await sendEmail({
  to: 'user@example.com',
  subject: 'Your newsletter',
  html,
});

Previewing in an Iframe

function Preview({ doc }: { doc: EmailDocument }) {
  const html = renderEmailDocument(doc);

  return (
    <iframe
      srcDoc={html}
      style={{ width: '100%', height: 600, border: 'none' }}
      title="Preview"
    />
  );
}