mrmlgo

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 4 Imported by: 0

README

MRML Go

Go Reference GitHub License

A Go wrapper for MRML, the MJML markup language implemented in rust.

Installation

go get github.com/codedninja/mrmlgo

Usage

package main

import (
	"fmt"
	"github.com/codedninja/mrmlgo"
)

func main() {
    mjml := `
    <mjml>
        <mj-body>
        <mj-section>
        <mj-column>
            <mj-image width="100px" src="/assets/img/logo-small.png"></mj-image>

            <mj-divider border-color="#F45E43"></mj-divider>

            <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text>
        </mj-column>
        </mj-section>
    </mj-body>
    </mjml>`


    options, _ := mrmlgo.NewParseOptions(map[string]string{})
    parsed, _ := mrmlgo.ParseMJML(mjml)

    html, _ := parsed.ToHTML();
    
    fmt.Println(html)
}
Detailed Usage

At the this current moment mrmlgo only supports in memory includes. You can pass a map[string]string when creating calling NewParseOptions. The format is ``map[filename]contents`.

package main

import (
	"fmt"
	"github.com/codedninja/mrmlgo"
)

func main() {
	includes := map[string]string{
		"hello-world.mjml": "<mj-text>Hello World</mj-text>",
	}

    mjml := `
    <mjml>
        <mj-body>
            <mj-include path="hello-world.mjml" />
        </mj-body>
    </mjml>`

	options, _ := mrmlgo.NewParseOptions(includes)
    parsed, _ := options.ParseMJML(mjml); 
    output, _ := parsed.ToHTML();

	fmt.Println("Output:", output)
}

Contributing

Coming soon.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • mrml - MJML Crate
  • mjml - The only framework that makes responsive emails easy.

Support

If you encounter any issues or have questions, please open an issue.

TODO

  • Github workflow for building rust libraries
  • Add tests

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParserOptions

type ParserOptions struct {
	// contains filtered or unexported fields
}

func NewParseOptions

func NewParseOptions(includeLoaders map[string]string) (*ParserOptions, error)

func (*ParserOptions) Destory

func (c *ParserOptions) Destory()

func (*ParserOptions) ParseJSON

func (c *ParserOptions) ParseJSON(input string) (*ParserOutput, error)

func (*ParserOptions) ParseMJML

func (c *ParserOptions) ParseMJML(input string) (*ParserOutput, error)

type ParserOutput

type ParserOutput struct {
	// contains filtered or unexported fields
}

func (*ParserOutput) Destory

func (c *ParserOutput) Destory()

func (*ParserOutput) ToHTML

func (c *ParserOutput) ToHTML() (string, error)

func (*ParserOutput) ToJSON

func (c *ParserOutput) ToJSON() (string, error)

func (*ParserOutput) ToMJML

func (c *ParserOutput) ToMJML() (string, error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL