-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DO NOT MERGE] feat!: css inlining in as_raw_html()
#498
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #498 +/- ##
==========================================
- Coverage 90.65% 90.63% -0.02%
==========================================
Files 45 45
Lines 5359 5402 +43
==========================================
+ Hits 4858 4896 +38
- Misses 501 506 +5 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From pairing, we're going to start a new PR for this, since reconciling Ruff accidentally produced many file changes
edit: here is the original diff before the ruff changes were applied: main...5ad0ae3
Thanks for this PR guys! Do you think it will make it into the next release by any chance? |
@Yasin197 I think there's a very good chance of that! |
as_raw_html()
as_raw_html()
as_raw_html()
as_raw_html()
This addition to the
as_raw_html()
method adds theinline_css=
argument. This option will inline CSS styles to the associated tags and remove the<style>...</style>
block from the HTML fragment. It'll be helpful for situations where you'd need to include an HTML table in an email message body (requires CSS inlining) or for embedding a table in a larger HTML document (could help to preserve more of the table's styling properties).Having this new feature requires a new dependency:
css_inline
. But it does a great job with CSS inlining both with a complete document and also with an HTML fragment (both modes are used here since there is amake_page=
argument inas_raw_html()
).Here's an example for how this works in practice:
Here is the table HTML without the CSS-inlining:
With
inline_css=True
, we get the styles inlined into thestyle
attributes of the appropriate tags:Notice that the CSS-inliner does not remove existing style rules from tags. Rather styles from the
<style>
block are prepended to the existing rules.Fixes: #497