Border_Style_Postprocessor
in package
implements
Postprocessor
Postprocessor that handles border-style declarations to ensure consistent rendering across email clients.
This postprocessor addresses two main issues:
-
Normalize border-style declarations: When using a uniform border-style declaration with non-uniform border-widths, some email clients (like Outlook) will incorrectly display borders on all sides even when the width is 0. For example:
border-color: #000000; border-style: solid; border-width: 0 1px 0 0;
would render borders on all sides in Outlook. This postprocessor normalizes the border-style declarations to only set styles for sides where border-width > 0:border-color: currentColor; border-width: 0 1px 0 0; border-right-style: solid;
-
Add fallback border styles: The block editor provides a default solid style for borders that have a width but no style specified. This postprocessor adds the same
border-style: solid
fallback to ensure the email rendering matches what users see in the editor.
The postprocessor handles all border cases including:
- Shorthand border declarations (border: 1px solid black)
- Individual side declarations (border-top, border-right, etc.)
- Individual property declarations (border-width, border-style, etc.)
- Mixed combinations of the above
Interfaces, Classes and Traits
- Postprocessor
- Interface for postprocessors.
Table of Contents
- postprocess() : string
- Postprocess the HTML.
- expand_shorthand_value() : array<string, string>
- Expands shorthand border width and style values into individual properties.
- extract_style_from_shorthand_value() : string|null
- Extracts the style from a shorthand value.
- extract_width_from_shorthand_value() : string|null
- Extracts the width from a shorthand value.
- is_nonzero_width() : bool
- Checks if a border width is nonzero.
- process_style() : string
- Processes a style string to ensure border-style is set for borders with width > 0 and removes extra border-style properties.
Methods
postprocess()
Postprocess the HTML.
public
postprocess(string $html) : string
Parameters
- $html : string
-
HTML to postprocess.
Return values
string —expand_shorthand_value()
Expands shorthand border width and style values into individual properties.
private
expand_shorthand_value(string $value) : array<string, string>
Parameters
- $value : string
-
The shorthand border value.
Return values
array<string, string> — The expanded border values.extract_style_from_shorthand_value()
Extracts the style from a shorthand value.
private
extract_style_from_shorthand_value(string $value) : string|null
Parameters
- $value : string
-
The shorthand value.
Return values
string|null — The extracted style or null if no style is found.extract_width_from_shorthand_value()
Extracts the width from a shorthand value.
private
extract_width_from_shorthand_value(string $value) : string|null
Parameters
- $value : string
-
The shorthand value.
Return values
string|null — The extracted width or null if no width is found.is_nonzero_width()
Checks if a border width is nonzero.
private
is_nonzero_width(string $width) : bool
Parameters
- $width : string
-
The width value.
Return values
bool —process_style()
Processes a style string to ensure border-style is set for borders with width > 0 and removes extra border-style properties.
private
process_style(string $style) : string
Parameters
- $style : string
-
The style attribute value.