email/emailinlinestylestransformations
Interfaces
module:email/emailinlinestylestransformations~EmailInlineStylesTransformationsOptions
Functions
getEmailInlineStylesTransformations( options ) → Array<ExportInlineStylesTransformation>module:email/emailinlinestylestransformations~getEmailInlineStylesTransformationsReturns a collection of style property transformations designed for email compatibility.
These transformations convert modern CSS styles into HTML attributes better supported by email clients. The transformations focus on converting alignment-related CSS properties into corresponding HTML attributes.
Examples of transformations:
Float to align:
<img style="float: left">→<img align="left">
Shorthand margin for centering:
<table style="margin: auto"></table>→<table style="..." align="center"></table><table style="margin: 10px auto"></table>→<table style="..." align="center"></table>
Note:
- The
alignattribute is only applied to thetableand theimgelements. - The
alignattribute overrides any existing alignment attributes on these elements. - If the
floatandmarginare present, thefloatproperty takes precedence for alignment. - The style attributes remain unchanged.
Parameters
options : EmailInlineStylesTransformationsOptionsConfiguration options.
Defaults to
{}
Returns
Array<ExportInlineStylesTransformation>An array of transformations to be applied to style properties for email compatibility.
transformEmailFigcaptionToDiv( element ) → HTMLElement | undefinedmodule:email/emailinlinestylestransformations~transformEmailFigcaptionToDivTransforms a FIGCAPTION element into a DIV element to make it more compatible with email clients.
Parameters
element : ElementThe element to transform.
Returns
HTMLElement | undefinedThe new DIV element or
undefinedif no transformation was applied.
transformEmailFigureToTable( element, stylesMap ) → HTMLElement | undefinedmodule:email/emailinlinestylestransformations~transformEmailFigureToTableReplacing the
<figure>element with one or two tables to handle alignment and width for better email compatibility.Examples:
<figure style="margin: auto; width: 600px;">→<table width="100%"><tr><td align="center"><table width="600px"><tr><td><div>...<figure style="margin-left: auto; width: 400px;">→<table width="100%"><tr><td align="right"><table width="400px"><tr><td><div>...<figure style="margin: auto;">→<table width="100%"><tr><td align="center"><div>...
Parameters
element : ElementThe element to transform.
stylesMap : StylesMapA map of CSS styles applied to the element.
Returns
HTMLElement | undefined
transformEmailFloatToAlign( element, stylesMap ) → voidmodule:email/emailinlinestylestransformations~transformEmailFloatToAlignTransform float: left/right to align="left"/"right" for table and img elements.
Examples:
<table style="float: left">→<table style="float: left" align="left"><img style="float: right">→<img style="float: right" align="right">
Parameters
element : ElementThe element to transform.
stylesMap : StylesMapA map of CSS styles applied to the element.
Returns
void
transformEmailImageWidthAttributes( element, stylesMap ) → voidmodule:email/emailinlinestylestransformations~transformEmailImageWidthAttributesRemoves width and height attributes from images that have width defined in styles. This helps to prevent issues with image scaling in some email clients.
Example:
<img style="width: 100px;" width="200" height="150">→<img style="width: 100px; height: auto;">
Parameters
element : ElementThe element to transform.
stylesMap : StylesMapA map of CSS styles applied to the element.
Returns
void
transformEmailMarginToAlign( element, stylesMap ) → voidmodule:email/emailinlinestylestransformations~transformEmailMarginToAlignHandle margin-left and margin-right combinations for alignment of the table element. It skips elements with float style because float has higher priority for alignment.
Examples:
<table style="margin-left: auto; margin-right: auto">→<table style="..." align="center"><table style="margin-left: auto">→<table style="..." align="right"><table style="margin-right: auto">→<table style="..." align="left">
Parameters
element : ElementThe element to transform.
stylesMap : StylesMapA map of CSS styles applied to the element.
Returns
void