Documentation
¶
Overview ¶
Package mjml provides the core MJML component system and rendering functionality. It converts parsed MJML AST nodes into renderable components that generate HTML output.
Index ¶
- Variables
- func Render(mjmlContent string, opts ...RenderOption) (string, error)
- func RenderComponentString(c Component) (string, error)
- func RenderFromAST(ast *MJMLNode, opts ...RenderOption) (string, error)
- func SetASTCacheCleanupIntervalOnce(d time.Duration)
- func SetASTCacheTTLOnce(d time.Duration)
- func StopASTCacheCleanup()
- type Component
- type Error
- type ErrorDetail
- type MJMLComponent
- type MJMLNode
- type RenderOption
- type RenderOpts
- type RenderResult
Constants ¶
This section is empty.
Variables ¶
var ParseMJML = parser.ParseMJML
ParseMJML re-exports the parser function for convenience
Functions ¶
func Render ¶
func Render(mjmlContent string, opts ...RenderOption) (string, error)
Render provides the main MJML to HTML conversion function
func RenderComponentString ¶ added in v0.1.2
RenderComponentString renders the given Component to a string. It creates a strings.Builder writer and passes it to the Component's Render method. This function returns the rendered output as a string, or an error if rendering fails. Where possible, it is recommended to use the component's Render function directly for better performance and flexibility.
func RenderFromAST ¶
func RenderFromAST(ast *MJMLNode, opts ...RenderOption) (string, error)
RenderFromAST renders HTML from a pre-parsed AST
func SetASTCacheCleanupIntervalOnce ¶ added in v0.5.0
SetASTCacheCleanupIntervalOnce sets how often expired AST cache entries are removed. Only the first call has an effect. By default this is half of the AST cache TTL.
func SetASTCacheTTLOnce ¶ added in v0.5.0
SetASTCacheTTLOnce sets the time-to-live for cached AST entries. Only the first call has an effect; subsequent calls are ignored. The cleanup interval defaults to half of this value unless explicitly set.
func StopASTCacheCleanup ¶ added in v0.5.0
func StopASTCacheCleanup()
StopASTCacheCleanup stops the background cache cleanup goroutine.
Types ¶
type Component ¶
type Component = components.Component
Component is an alias for the components.Component interface
func CreateComponent ¶
CreateComponent creates a component from an MJML AST node
func NewFromAST ¶
func NewFromAST(ast *MJMLNode, opts ...RenderOption) (Component, error)
NewFromAST creates a component from a pre-parsed AST (alias for CreateComponent)
type Error ¶ added in v0.10.0
type Error struct {
Message string `json:"message"`
Details []ErrorDetail `json:"details"`
}
Error addresses errors that occur during the compilation of MJML to HTML. It represents errors returned by the MJML engine, providing a general message and a list of detailed errors, each including the line number, error message, and the tag name where the error occurred.
Error is a direct re-interprtation of the same type present in https://github.com/Boostport/mjml-go
func ErrInvalidAttribute ¶ added in v0.10.0
type ErrorDetail ¶ added in v0.10.0
type ErrorDetail struct {
Line int `json:"line"`
Message string `json:"message"`
TagName string `json:"tagName"`
}
ErrorDetail represents a single error detail with line number, message, and tag name.
type MJMLComponent ¶
type MJMLComponent struct {
*components.BaseComponent
Head *components.MJHeadComponent
Body *components.MJBodyComponent
// contains filtered or unexported fields
}
MJMLComponent represents the root MJML component
func (*MJMLComponent) GetTagName ¶
func (c *MJMLComponent) GetTagName() string
func (*MJMLComponent) RegisterCarouselCSS ¶ added in v0.4.0
func (c *MJMLComponent) RegisterCarouselCSS(css string)
RegisterCarouselCSS allows carousel components to register their CSS
func (*MJMLComponent) Render ¶
func (c *MJMLComponent) Render(w io.StringWriter) error
Render implements optimized Writer-based rendering for MJMLComponent
func (*MJMLComponent) RequestMobileCSS ¶
func (c *MJMLComponent) RequestMobileCSS()
RequestMobileCSS allows components to request mobile CSS to be added
type RenderOption ¶
type RenderOption func(*RenderOpts)
RenderOption is a functional option for configuring MJML rendering
func WithDebugTags ¶
func WithDebugTags(enabled bool) RenderOption
WithDebugTags enables or disables debug tag inclusion in the rendered output
type RenderResult ¶
RenderResult contains both the rendered HTML and the MJML AST
func RenderWithAST ¶
func RenderWithAST(mjmlContent string, opts ...RenderOption) (*RenderResult, error)
RenderWithAST provides the internal MJML to HTML conversion function that returns both HTML and AST
Directories
¶
| Path | Synopsis |
|---|---|
|
Package debug provides logging functionality for development and troubleshooting.
|
Package debug provides logging functionality for development and troubleshooting. |
|
Package html provides utilities for generating email-compatible HTML from MJML components.
|
Package html provides utilities for generating email-compatible HTML from MJML components. |
|
Package options contains render options for MJML components
|
Package options contains render options for MJML components |
|
Package styles provides utilities for parsing and applying CSS values to HTML elements.
|
Package styles provides utilities for parsing and applying CSS values to HTML elements. |