-
Notifications
You must be signed in to change notification settings - Fork 15
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
html2htpy includes unneccessary white space #74
Comments
I remember concidering to strip the strings, but decided against it for some reason. Cant quite recall why, but might have had to do with some cases where I actually preferred whitespace to stay as is. Possibly theres some quirks with this in multi line strings. I can take a look |
I am not sure what the best exact rules would be, not all white space are safe to remove. I guess there are html minifiers and similar that could be used as inspiration for how to properly strip some of the whitespace |
One special case at least would be |
Another thing to consider here; other html tags also can have goofy behavior as relates to css properties such as To play around a bit, I made a codepen based on this mdn example that showcases a couple of cases where we would not want (all) whitespace trimmed. Below is a little teaser: <!-- Example: Newlines preserved -->
<h2 style="white-space-collapse: preserve-breaks;">
In this case
all the newlines are preserved
in the heading,
but spaces are collapsed .
</h2> One option might be to filter for these properties and handle them in a special way. I'm not sure if I'd recommend it though, as it might quickly get complicated. w3 spec defines a non trivial set of white space processing rules that we should probably try to abide by if we do decide to do some trimmin'. Edit to add: These properties might also be inherited or assigned with a class as in the code-pen, so it would be impossible to accurately recognize when they're applied to a given string. |
An option might be to disregard the css props and trim away, though leave |
What about:
When copy/pasting HTML code from the internet, it is often filled with spaces/white space that makes the HTML document look nice but is just there because it makes the HTML source look good rather then required from a functionality point of view. |
To be clear: I do not think we should bother about |
I agree with your comments, and this should be pretty simple to implement I guess. I have some time and can bring a PR tomorrow? |
That is very welcome! :) |
it would be nicer of the output was just
p["Hi"]
The text was updated successfully, but these errors were encountered: