diff --git a/great_tables/_export.py b/great_tables/_export.py index cebb082a3..ef03b8ed4 100644 --- a/great_tables/_export.py +++ b/great_tables/_export.py @@ -9,8 +9,10 @@ from pathlib import Path from typing import TYPE_CHECKING, Literal +from css_inline import inline, inline_fragment from typing_extensions import TypeAlias +from ._helpers import random_id from ._utils import _try_import from ._utils_render_latex import _render_as_latex @@ -111,7 +113,7 @@ def show( html, raw=True, metadata={"text/html": {"isolated": True}} ) elif target == "browser": - html = self.as_raw_html(make_page=True) + html = self.as_raw_html(inline_css=False, make_page=True) with tempfile.TemporaryDirectory() as tmp_dir: f_path = Path(tmp_dir) / "index.html" f_path.write_text(html, encoding="utf-8") @@ -126,19 +128,29 @@ def show( def as_raw_html( self: GT, + inline_css: bool = True, make_page: bool = False, all_important: bool = False, ) -> str: """ Get the HTML content of a GT object. - Get the HTML content from a GT object as a string. This function is useful for obtaining the - HTML content of a GT object for use in other contexts. + Get the HTML content from a GT object as a string. By default, the generated HTML will have + inlined styles, where CSS styles (that were previously contained in CSS rule sets external to + the `` element are included as style attributes in the HTML table's tags. This option is + preferable when using the output HTML table in an emailing context. Parameters ---------- gt A GT object. + inline_css + An option to supply styles to table elements as inlined CSS styles. This is useful when + including the table HTML as part of an HTML email message body, since inlined styles are + largely supported in email clients over using CSS in a `