Skip to content

Feature: configurable <body> background in Render.render_email (#19)#21

Draft
makerprism-bot wants to merge 1 commit into
mainfrom
automation/issue-19-f7dc92b1
Draft

Feature: configurable <body> background in Render.render_email (#19)#21
makerprism-bot wants to merge 1 commit into
mainfrom
automation/issue-19-f7dc92b1

Conversation

@makerprism-bot
Copy link
Copy Markdown
Contributor

Fixes #19.

Automated implementation for issue #19 (#19).

Produced by automation run f7dc92b1-ff3b-4036-8192-fd69d5f21cda using Claude Code on makerprism/typemail.

Agent's summary (last lines of output):

Implementation complete. The `Render.render_email` function now accepts an optional `body_background` parameter that allows customizing the `<body>` element's background color.

**Changes made:**
- `lib/render.mli`: Added `?body_background:Color.t` parameter with documentation
- `lib/render.ml`: Implemented the parameter with default `Color.solid "#ffffff"` for backward compatibility
- Uses `Color.to_style` for proper CSS generation (supports both solid colors and gradients)
- Adds `bgcolor` attribute for Outlook gradient fallback

**Example usage:**
```ocaml
(* Solid background *)
Render.render_email
  ~body_background:(Color.solid "#f9fafb")
  body_element

(* Gradient background with fallback *)
Render.render_email
  ~body_background:(Color.gradient
    ~direction:"to bottom"
    ~colors:["#f3f4f6"; "#ffffff"]
    ~fallback:(Color.solid "#f3f4f6"))
  body_element

Committed changes to branch automation/issue-19-f7dc92b1.


Review carefully; this is a first-attempt automated change.

Add optional body_background parameter to Render.render_email to allow
customizing the <body> element's background color. This enables the
common transactional email pattern of tinted page backgrounds with
lighter content cards inside.

- Add ?body_background:Color.t parameter (defaults to solid white)
- Generate proper background styles using Color.to_style
- For gradients, add bgcolor attribute with fallback color for Outlook
- Backward compatible: defaults to existing behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@sabine sabine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Request Changes

Thanks for the body_background feature! This is a useful addition. However, there's a critical bug with nested gradient handling that needs to be fixed.

Critical Issue: Nested Gradient Fallback

Current code:

| Color.Gradient {fallback = Gradient _; _} ->
    (* Should be impossible through API, but handle gracefully *)
    " bgcolor=\"#ffffff\""

Problem: This pattern is possible when users nest gradients:

let nested = Color.gradient
  ~colors:["#667eea"; "#764ba2"]
  ~fallback:(Color.gradient  (* <-- Nested gradient *)
    ~colors:["#a18cd1"; "#fbc2eb"]
    ~fallback:(Color.solid "#667eea"))

The code returns #ffffff instead of extracting the solid fallback from the nested gradient.

Fix:

(* Extract solid fallback from potentially nested gradients *)
let rec extract_solid_fallback = function
  | Color.Solid hex -> hex
  | Color.Gradient {fallback; _} -> extract_solid_fallback fallback
in

let bgcolor_attr = match body_background with
  | Color.Solid hex -> Printf.sprintf " bgcolor=\"%s\"" hex
  | Color.Gradient _ -> 
      let fb_hex = extract_solid_fallback body_background in
      Printf.sprintf " bgcolor=\"%s\"" fb_hex

Additional Requests

  1. Add caniemail citation for body background support

  2. Add test coverage for:

    • Solid body background
    • Gradient body background with fallback
    • Nested gradient fallback extraction (critical)
    • Verify bgcolor attribute is correctly extracted
  3. Documentation: Update module doc to mention body_background parameter in examples

Summary

The feature is good but needs the nested gradient bug fixed before merging. Once that's addressed and tests are added, this will be ready to merge.

@makerprism-bot makerprism-bot marked this pull request as draft April 19, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: configurable <body> background in Render.render_email

2 participants