Skip to content

write_html: ignore a transparent color or bgcolor, like browsers - #2010

Merged
andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:html-color-transparent
Oct 12, 2026
Merged

andersonhc merged 3 commits into
py-pdf:masterfrom
RavSinghChandan:html-color-transparent

Conversation

@RavSinghChandan

@RavSinghChandan RavSinghChandan commented Oct 12, 2026 •

Copy link
Copy Markdown

bgcolor="transparent" or <font color="transparent"> raised ValueError: transparent does not start with #. In HTML color attributes, "transparent" is an error that browsers ignore, so the element keeps its normal color and no background. color_as_decimal() now returns None for it, the same as an empty color. Added tests for color and bgcolor on <font>, <tr> and <td>.

e.g. Fixes #0

Checklist:

  • A unit test is covering the code added / modified by this PR

  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder

  • A mention of the change is present in CHANGELOG.md

  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

@andersonhc andersonhc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please make sure transparent is not being handled as use default color.

<font color="red">a<font color="transparent">b</font>c</font> - should print ab in red

<table><tr bgcolor="red"><td bgcolor="transparent">a</td></tr></table> should have red background

Comment thread test/html/test_html.py Resolved
@RavSinghChandan

Copy link
Copy Markdown
Author

You're right, thanks! transparent is now treated as if the attribute wasn't set, so the inherited color is kept: in abc all of it stays red, and keeps the red background, empty cells included. I added both as tests.

@andersonhc
andersonhc merged commit 49d1b3d into py-pdf:master Oct 12, 2026
29 of 42 checks passed
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.

2 participants