API Reference
Complete API documentation for Email.md.
render(markdown, options?)
Renders markdown to email-safe HTML.
Returns { html, text, meta }
html— complete HTML email documenttext— plain text version for thetext/plainMIME partmeta— extracted frontmatter metadata
import { render } from "emailmd";
const { html, text, meta } = render("# Hello");RenderOptions
{
theme?: Partial<Theme>;
wrapper?: 'default' | WrapperFn;
}| Option | Type | Description |
|---|---|---|
theme | Partial<Theme> | Override default theme values |
wrapper | 'default' | WrapperFn | Custom email wrapper function |
RenderResult
{
html: string;
text: string;
meta: { preheader?: string; [key: string]: unknown };
}| Property | Type | Description |
|---|---|---|
html | string | Complete email-safe HTML document |
text | string | Plain text version |
meta | object | Extracted frontmatter metadata |
Theme
The full theme interface with all customizable properties:
interface Theme {
brandColor: string; // Links, highlights, accents
headingColor: string; // Heading text
bodyColor: string; // Body text
backgroundColor: string; // Outer background
contentColor: string; // Content area background
cardColor: string; // Callout / code block background
buttonColor: string; // Primary button background
buttonTextColor: string; // Button text
fontFamily: string; // Font stack
fontSize: string; // Base font size (e.g. "16px")
lineHeight: string; // Base line height (e.g. "1.6")
contentWidth: string; // Email width (e.g. "600px")
}Pass a Partial<Theme> to render() to override any subset of values. See Theme for defaults.
darkTheme
A pre-built dark theme object. Import and pass directly or spread with overrides:
import { render, darkTheme } from "emailmd";
// Use as-is
render(md, { theme: darkTheme });
// Override specific values
render(md, { theme: { ...darkTheme, brandColor: "#e11d48" } });buildHead(theme, preheader?)
function buildHead(theme: Theme, preheader?: string): string;Generates the MJML <mj-head> element containing global styles, font imports, and the hidden preheader text. Used when building custom wrappers.
segmentsToMjml(segments, theme)
function segmentsToMjml(segments: Segment[], theme: Theme): string;Converts parsed content segments into MJML body elements (sections, columns, text, buttons, images, tables, etc.). Used when building custom wrappers.
Segment
interface Segment {
type: 'text' | 'callout' | 'centered' | 'highlight' | 'header' | 'footer'
| 'button' | 'button-group' | 'image' | 'hr' | 'table' | 'hero';
content: string;
attrs?: Record<string, string>;
buttons?: Array<Record<string, string>>;
}Represents a parsed block of content from the markdown. The segments array is what gets passed to segmentsToMjml and to custom wrapper functions.
WrapperFn
type WrapperFn = (
segments: Segment[],
theme: Theme,
meta?: Record<string, unknown>,
) => string;A function that receives parsed segments, the resolved theme, and frontmatter metadata, and returns a complete MJML string. See Wrappers for usage examples.