render-mjml-go is a Go implementation of MJML rendering.
It parses MJML markup and produces responsive HTML for email clients.
- Core MJML rendering package:
mjml - XML/MJML parser package:
parser - CLI tool:
cmd/gomjml - Integration fixtures and component tests in
mjml/testdata - Example apps in
examples/basicandexamples/sendmail
- Render MJML to HTML with
mjml.Render - Parse MJML to AST with
parser.ParseMJML - Build/render from AST directly (
CreateComponent,RenderComponentString,RenderFromAST) - Optional debug tags in output (
mjml.WithDebugTags(true)) - Optional AST cache for repeated renders (
mjml.WithCache()) - Configurable cache timing (
SetASTCacheTTLOnce,SetASTCacheCleanupIntervalOnce)
go get github.com/turtlepavlo/render-mjml-gopackage main
import (
"fmt"
"log"
"github.com/turtlepavlo/render-mjml-go/mjml"
)
func main() {
input := `<mjml><mj-body><mj-section><mj-column><mj-text>Hello!</mj-text></mj-column></mj-section></mj-body></mjml>`
html, err := mjml.Render(input)
if err != nil {
log.Fatal(err)
}
fmt.Println(html)
}ast, err := parser.ParseMJML(input)
if err != nil {
return err
}
component, err := mjml.CreateComponent(ast, nil)
if err != nil {
return err
}
html, err := mjml.RenderComponentString(component)
if err != nil {
return err
}Build and run the CLI:
go run ./cmd/gomjml compile input.mjml -o output.htmlRender to stdout:
go run ./cmd/gomjml compile input.mjml -sEnable debug attributes and cache:
go run ./cmd/gomjml compile input.mjml --debug --cache --cache-ttl 10m --cache-cleanup-interval 5mRun MJML test suite:
go run ./cmd/gomjml test -vRun all tests:
go test ./...Format code:
gofmt -w ./...mjml/rendering engine, components, styles, integration testsparser/MJML parsing and AST utilitiescmd/gomjml/user-facing command-line interfacecmd/htmlcompare/local HTML comparison helpercmd/utils/extract-defaults/utility for extracting default attributes from MRML sourcesexamples/minimal usage examples
- The module path is
github.com/turtlepavlo/render-mjml-go. - The project is test-driven with many fixture-based compatibility checks.
- The renderer supports a wide set of MJML components and email-client-specific output behavior.