Skip to content

Post-Render Transformers — HTML Processing Pipeline

The transformer pipeline lets you modify rendered HTML before it reaches consumers (email channels, PDF generators). This is particularly useful for email templates, where you need table-based layout, inline CSS, and Outlook conditional comments — concerns that template authors should not deal with manually.

public interface IRenderedContentTransformer
{
int Order { get; }
bool CanTransform(DocumentFormat format);
Task<string> TransformAsync(string content, DocumentFormat format, CancellationToken ct);
}

Transformers run as an ordered mutation chain: each receives the output of the previous one and returns modified content. Use CanTransform to restrict a transformer to specific formats (e.g., HTML-only, skip PDF/Excel).

services.AddRenderedContentTransformer<HtmlMinificationTransformer>();
public sealed class HtmlMinificationTransformer : IRenderedContentTransformer
{
public int Order => 300;
public bool CanTransform(DocumentFormat format) => format == DocumentFormat.Html;
public Task<string> TransformAsync(
string content, DocumentFormat format, CancellationToken ct)
{
// Your minification logic here
return Task.FromResult(Minify(content));
}
}
RangePurposeExample
100Structural transformationMJML compilation
200CSS processingInlining, purging
300+CosmeticMinification, cleanup

The built-in MjmlTransformer (Order=100) runs first to convert MJML markup into table-based HTML. Application-level transformers should use Order 200+ to process the already-compiled HTML. See MJML Email Templates for details on the MJML transformer, and Rendering Pipeline for how transformers fit into the five-stage pipeline.