Skip to content

Commit

Permalink
Merge pull request #454 from jrycw/encoding-issue-GT-save
Browse files Browse the repository at this point in the history
Update `GT.save()`
  • Loading branch information
rich-iannone authored Sep 18, 2024
2 parents fa8df51 + 779361d commit 0af5fe4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions great_tables/_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def save(
web_driver: WebDrivers = "chrome",
window_size: tuple[int, int] = (6000, 6000),
debug_port: None | int = None,
encoding: str = "utf-8",
_debug_dump: DebugDumpOptions | None = None,
) -> None:
"""
Expand Down Expand Up @@ -215,6 +216,8 @@ def save(
to capture a table, but may affect the tables appearance.
debug_port
Port number to use for debugging. By default no debugging port is opened.
encoding
The encoding used when writing temporary files.
_debug_dump
Whether the saved image should be a big browser window, with key elements outlined. This is
helpful for debugging this function's resizing, cropping heuristics. This is an internal
Expand Down Expand Up @@ -255,11 +258,8 @@ def save(
if selector != "table":
raise NotImplementedError("Currently, only selector='table' is supported.")

# Get the file extension from the file name
file_extension = file.split(".")[-1]

# If there is no file extension, add the .png extension
if len(file_extension) == len(file):
if not Path(file).suffix:
file += ".png"

# Get the HTML content from the displayed output
Expand Down Expand Up @@ -306,11 +306,11 @@ def save(
):

# Write the HTML content to the temp file
with open(f"{tmp_dir}/table.html", "w") as temp_file:
with open(f"{tmp_dir}/table.html", "w", encoding=encoding) as temp_file:
temp_file.write(html_content)

# Open the HTML file in the headless browser
headless_browser.set_window_size(window_size[0], window_size[1])
headless_browser.set_window_size(*window_size)
headless_browser.get("file://" + temp_file.name)

_save_screenshot(headless_browser, scale, file, debug=_debug_dump)
Expand Down

0 comments on commit 0af5fe4

Please sign in to comment.