feat: css inlining in as_raw_html()
#498
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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