Documentation
¶
Overview ¶
Package mjml works with MJML documents on the server: a tolerant parser for outlines, warnings and wireframes, the server-side compiler (gomjml, MJML 4.15) used when content arrives as MJML only (API and automation sends), and head helpers that keep <mj-title>/<mj-preview> in step with the subject and preheader.
The composer compiles in the browser with mjml-browser (grapesjs-mjml); both engines target MJML 4 and parity is checked by tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangedSections ¶
ChangedSections compares two documents and returns the labels of the sections of `next` that differ from `base` (added, edited or moved), plus the labels of sections removed from base.
func SectionLabel ¶
SectionLabel names a top-level body element: the ReputeCast marker when there is one, otherwise what it looks like.
func SetHeadMeta ¶
SetHeadMeta writes <mj-title> (the subject) and <mj-preview> (the preheader) into a document so the compiled HTML's title and hidden preview text always match the fields. Empty values remove the element. A document that doesn't parse is returned unchanged.
Types ¶
type MJMLProblem ¶
type MJMLProblem struct {
Line int `json:"line"`
Message string `json:"message"`
Tag string `json:"tag,omitempty"`
}
MJMLProblem is a compile error or warning with its line (0 when unknown).
func Lint ¶
func Lint(src string) []MJMLProblem
Lint returns layout warnings the MJML compiler doesn't report: images wider than their column (Outlook draws them at full width and breaks the layout) and columns adding up to more than their section.
type MJMLThumbItem ¶
type MJMLThumbItem struct {
H int `json:"h,omitempty"`
W int `json:"w,omitempty"`
Accent bool `json:"accent,omitempty"`
Row []MJMLThumbItem `json:"row,omitempty"`
}
MJMLThumbItem is one bar of a template's wireframe thumbnail in the gallery: a grey block of height H (px) and width W (% of the thumbnail; 0 = full), an accent pill for buttons, or a row of blocks for columns.
func Thumb ¶
func Thumb(src string) []MJMLThumbItem
Thumb derives the gallery wireframe from a document: a short bar for the header, a block for a hero image, a row of blocks for columns, lines for text and a pill for a button. It keeps at most five items and stops at the first one that doesn't fit the thumbnail, so no bar is cut off.
type Node ¶
type Node struct {
Tag string
Attrs []Attr
Children []*Node
// Inner is the raw content of ending tags (mj-text, mj-button, mj-raw…),
// which hold HTML rather than MJML elements.
Inner string
// Marker is the ReputeCast block a preceding <!-- rc:… --> comment names
// ("footer", "header-logo"), empty otherwise.
Marker string
// Line is the 1-based line of the opening tag.
Line int
// Start and End are byte offsets of the element in the source.
Start, End int
}
Node is one element of an MJML document.
func Parse ¶
Parse reads an MJML document and returns its <mjml> root. It is lenient about whitespace, attribute quoting, comments and void tags, and reports tags that are never closed with their line.
type ParseError ¶
ParseError is a syntax problem with its line.
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Result ¶
type Result struct {
HTML string
Errors []MJMLProblem
Duration time.Duration
}
Result is the outcome of a server-side compile.
type Section ¶
type Section struct {
// Index is the position among mj-body's elements (comments excluded).
Index int `json:"index"`
Tag string `json:"tag"`
// Label names the section the way the layer tree does: "header", "hero",
// "2 columns", "text", "footer".
Label string `json:"label"`
// Marker is the ReputeCast block it was inserted from ("footer"), if any.
Marker string `json:"marker,omitempty"`
Line int `json:"line"`
// Hash fingerprints the section's source, to tell which sections changed
// between two versions.
Hash string `json:"-"`
}
Section is one top-level block of <mj-body>.