Skip to content
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

is there a way to stop wrapping of html_str? #140

Open
jtauber opened this issue Feb 11, 2024 · 3 comments
Open

is there a way to stop wrapping of html_str? #140

jtauber opened this issue Feb 11, 2024 · 3 comments

Comments

@jtauber
Copy link

jtauber commented Feb 11, 2024

I noticed after a while using this library (when I set keep_temp_files=True) that my html_str is being wrapped as if it were just the body. I can see this is being done _prepare_html_string where the parameter is called html_body (which makes it clearer that it's just the body).

Is there any way to stop this wrapping and just pass in the full HTML?

Perhaps with a different argument?

@jtauber
Copy link
Author

jtauber commented Feb 11, 2024

My workaround is to just add the line:

Html2Image._prepare_html_string = lambda html, _: html

in my code.

@vgalin
Copy link
Owner

vgalin commented Feb 11, 2024

At the time, I did not consider that html_str would be used with something other than a very basic HTML string; it was more of a convenient way to transform a string into a valid HTML file than anything. But I indeed see cases where you could already have a full HTML file stored as a string and wouldn't want to transform it in any way.

Currently, there is no "right" way to disable this behavior; your workaround is probably the shortest/cleanest way to disable _prepare_html_string.

Another way could be to write your HTML strings to files directly and call the screenshot method using the html_file parameter, as the HTML files are not pre-processed in any way.

In any case, a simple boolean parameter allowing to disable this behavior would be nice; it will be added when I'll have access to my machine.

@jtauber
Copy link
Author

jtauber commented Feb 11, 2024

Thank you! Hopefully it's helpful to others too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants