Class MsoHelper

java.lang.Object
dev.jcputney.mjml.util.MsoHelper

public final class MsoHelper extends Object
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 Details

    • MSO_TD_STYLE

      public static final String MSO_TD_STYLE
      Standard MSO td style for resetting line-height.
      See Also:
    • MSO_TD_STYLE_HERO

      public static final String MSO_TD_STYLE_HERO
      Variant used by mj-hero (no trailing 'px' on line-height).
      See Also:
  • Method Details

    • conditionalStart

      public static String conditionalStart()
      Opens an MSO conditional comment block.
      Returns:
      <!--[if mso | IE]>
    • conditionalEnd

      public static String conditionalEnd()
      Closes an MSO conditional comment block.
      Returns:
      <![endif]-->
    • msoTableOpening

      public static String msoTableOpening(int width, String cssClass, String bgColor, String tdStyle)
      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 pixels
      cssClass - CSS class for the table (already escaped)
      bgColor - background color, or null/empty to omit bgcolor attribute
      tdStyle - style string for the inner td
      Returns:
      the MSO table opening markup (without conditional comments)
    • msoTableClosing

      public static String msoTableClosing()
      Builds an MSO table closing.
      Returns:
      </td></tr></table>
    • msoConditionalTableClosing

      public static String msoConditionalTableClosing()
      Builds a complete MSO table closing wrapped in conditional comments.
      Returns:
      <!--[if mso | IE]></td></tr></table><![endif]-->
    • msoWrapperNestedOpening

      public static String msoWrapperNestedOpening(int containerWidth, int innerWidth)
      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 pixels
      innerWidth - the computed inner width (container minus padding/borders)
      Returns:
      the MSO conditional opening markup
    • msoWrapperTransition

      public static String msoWrapperTransition(int containerWidth, int innerWidth)
      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 pixels
      innerWidth - the computed inner width (container minus padding/borders)
      Returns:
      the MSO conditional transition markup