Skip to content

turtlepavlo/render-mjml-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

render-mjml-go

render-mjml-go is a Go implementation of MJML rendering. It parses MJML markup and produces responsive HTML for email clients.

What this project includes

  • 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/basic and examples/sendmail

Key capabilities

  • 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)

Installation

go get github.com/turtlepavlo/render-mjml-go

Quick start (library)

package 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 workflow

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
}

CLI usage

Build and run the CLI:

go run ./cmd/gomjml compile input.mjml -o output.html

Render to stdout:

go run ./cmd/gomjml compile input.mjml -s

Enable debug attributes and cache:

go run ./cmd/gomjml compile input.mjml --debug --cache --cache-ttl 10m --cache-cleanup-interval 5m

Run MJML test suite:

go run ./cmd/gomjml test -v

Development

Run all tests:

go test ./...

Format code:

gofmt -w ./...

Repository layout

  • mjml/ rendering engine, components, styles, integration tests
  • parser/ MJML parsing and AST utilities
  • cmd/gomjml/ user-facing command-line interface
  • cmd/htmlcompare/ local HTML comparison helper
  • cmd/utils/extract-defaults/ utility for extracting default attributes from MRML sources
  • examples/ minimal usage examples

Notes

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages