Class MsoHelper
java.lang.Object
dev.jcputney.mjml.util.MsoHelper
Shared helpers for generating MSO/IE conditional comments used by
<mj-section>,
<mj-wrapper>, and <mj-hero>.
Outlook and IE do not support modern CSS layout, so MJML emits conditional-comment-wrapped tables to constrain widths. These helpers eliminate duplication of the boilerplate strings across components.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCloses an MSO conditional comment block.static StringOpens an MSO conditional comment block.static StringBuilds a complete MSO table closing wrapped in conditional comments.static StringBuilds an MSO table closing.static StringmsoTableOpening(int width, String cssClass, String bgColor, String tdStyle) Builds an MSO table opening with width constraint.static StringmsoWrapperNestedOpening(int containerWidth, int innerWidth) Builds the MSO conditional opening for the first child inside an mj-wrapper.static StringmsoWrapperTransition(int containerWidth, int innerWidth) Builds the MSO conditional transition markup between adjacent children inside an mj-wrapper.
-
Field Details
-
MSO_TD_STYLE
-
MSO_TD_STYLE_HERO
Variant used by mj-hero (no trailing 'px' on line-height).- See Also:
-
-
Method Details
-
conditionalStart
Opens an MSO conditional comment block.- Returns:
<!--[if mso | IE]>
-
conditionalEnd
Closes an MSO conditional comment block.- Returns:
<![endif]-->
-
msoTableOpening
Builds an MSO table opening with width constraint. Emits:<table align="center" border="0" cellpadding="0" cellspacing="0" class="{cssClass}" role="presentation" style="width:{width}px;" width="{width}" [bgcolor="{bgColor}"]><tr><td style="{tdStyle}">- Parameters:
width- container width in pixelscssClass- CSS class for the table (already escaped)bgColor- background color, or null/empty to omit bgcolor attributetdStyle- style string for the inner td- Returns:
- the MSO table opening markup (without conditional comments)
-
msoTableClosing
-
msoConditionalTableClosing
Builds a complete MSO table closing wrapped in conditional comments.- Returns:
<!--[if mso | IE]></td></tr></table><![endif]-->
-
msoWrapperNestedOpening
Builds the MSO conditional opening for the first child inside an mj-wrapper. Opens the outer table, a td with container width, an inner table with inner width, and a tr/td.- Parameters:
containerWidth- the wrapper's container width in pixelsinnerWidth- the computed inner width (container minus padding/borders)- Returns:
- the MSO conditional opening markup
-
msoWrapperTransition
Builds the MSO conditional transition markup between adjacent children inside an mj-wrapper. Closes the current inner table and td, then opens a new tr/td with container width and a new inner table with inner width.- Parameters:
containerWidth- the wrapper's container width in pixelsinnerWidth- the computed inner width (container minus padding/borders)- Returns:
- the MSO conditional transition markup
-