Skip to content

Commit

Permalink
Change default of inline_css= from True to False
Browse files Browse the repository at this point in the history
  • Loading branch information
rich-iannone committed Dec 10, 2024
1 parent c215cea commit d23eaf6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
25 changes: 15 additions & 10 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def show(
html, raw=True, metadata={"text/html": {"isolated": True}}
)
elif target == "browser":
html = self.as_raw_html(inline_css=False, make_page=True)
html = self.as_raw_html(make_page=True)
with tempfile.TemporaryDirectory() as tmp_dir:
f_path = Path(tmp_dir) / "index.html"
f_path.write_text(html, encoding="utf-8")
Expand All @@ -129,7 +129,7 @@ def show(

def as_raw_html(
self: GT,
inline_css: bool = True,
inline_css: bool = False,
make_page: bool = False,
all_important: bool = False,
) -> str:
Expand Down Expand Up @@ -195,21 +195,26 @@ def as_raw_html(
gt_tbl
```
Now we can return the table as an HTML string with inlined CSS styles using the `as_raw_html()`
method.
Now we can return the table as an HTML string using the `as_raw_html()` method.
```{python}
gt_tbl.as_raw_html()
```
The HTML string contains the HTML for the table. It has only the `<table>...</table>` part so
it's not a complete HTML document but rather an HTML fragment. While this useful for embedding
a table in an existing HTML document, you could also use the `make_page=True` argument to get a
complete HTML page with the table embedded in it. And if that's the case you might also want to
suppress the inlining of CSS styles by setting `inline_css=False`.
The HTML string contains the HTML for the table. It has only the table so it's not a complete
HTML document but rather an HTML fragment. While this useful for embedding a table in an
existing HTML document, you could also use the `make_page=True` argument to get a complete HTML
page with the table contained within.
```{python}
gt_tbl.as_raw_html(inline_css=False, make_page=True)
gt_tbl.as_raw_html(make_page=True)
```
Should you want to include all of the CSS styles as inline styles, you can use `inline_css=True`
to get an HTML string with all CSS inlined into the HTML tags.
```{python}
gt_tbl.as_raw_html(inline_css=True)
```
"""
built_table = self._build_data(context="html")
Expand Down
1 change: 0 additions & 1 deletion great_tables/gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def _repr_html_(self):
all_important = defaults["all_important"]

rendered = self.as_raw_html(
inline_css=False,
make_page=make_page,
all_important=all_important,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def gt_tbl_small():


def test_html_string_generated(gt_tbl: GT, snapshot: str):
assert snapshot == gt_tbl.as_raw_html(inline_css=False)
assert snapshot == gt_tbl.as_raw_html()


def test_html_string_generated_inline_css(gt_tbl_small: GT, snapshot: str):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_opt_table_font_use_stack_and_system_font():
def test_opt_table_font_google_font():
gt_tbl = GT(exibble).opt_table_font(font=google_font(name="IBM Plex Mono"))

rendered_html = gt_tbl.as_raw_html(inline_css=False)
rendered_html = gt_tbl.as_raw_html()

assert rendered_html.find(
"@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap');"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tab_create_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_tab_style_google_font(gt: GT):
locations=loc.body(columns="x"),
)

rendered_html = new_gt.as_raw_html(inline_css=False)
rendered_html = new_gt.as_raw_html()

assert rendered_html.find(
"@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&display=swap');"
Expand All @@ -55,7 +55,7 @@ def test_tab_style_font_local(gt: GT):
locations=loc.body(columns="x"),
)

rendered_html = new_gt.as_raw_html(inline_css=False)
rendered_html = new_gt.as_raw_html()

assert rendered_html.find('<td style="font-family: Courier;" class="gt_row gt_right">1</td>')

Expand All @@ -67,7 +67,7 @@ def test_tab_style_font_from_column():
style=style.text(font=from_column(column="font")), locations=loc.body(columns="x")
)

rendered_html = gt_tbl.as_raw_html(inline_css=False)
rendered_html = gt_tbl.as_raw_html()

assert rendered_html.find('<td style="font-family: Helvetica;" class="gt_row gt_right">1</td>')
assert rendered_html.find('<td style="font-family: Courier;" class="gt_row gt_right">2</td>')
2 changes: 1 addition & 1 deletion tests/test_utils_render_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,6 @@ def test_loc_kitchen_sink(snapshot):
.tab_style(style.css("STUBHEAD"), loc.stubhead())
)

html = new_gt.as_raw_html(inline_css=False)
html = new_gt.as_raw_html()
cleaned = html[html.index("<table") :]
assert cleaned == snapshot

0 comments on commit d23eaf6

Please sign in to comment.