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
Document that compressHTML
doesn't remove all whitespace
#7502
Comments
As far as I know, this is intended, |
Isn't it already changing the visual output by removing indentation? In any case, the current documentation is misleading. And it would be useful to still have at least an opt-in mode where all whitespace is collapsed (similar to JSX). Currently this does not seem achievable even with a Vite plugin ( |
No (well it's not supposed to at least?), because spaces in this context always get collapsed to one. That's why Prettier formats <span>
Something
</span> into <span> Something </span> because they end up with the same visual result, since the number of whitespace doesn't matter.
I agree, that'd be cool! Essentially turning the HTML into JSX, ha. |
Moving this issue to docs, since it's a docs issue in the end. It should be documented that |
@mayank99 Feel free to create a roadmap discussion https://github.com/withastro/roadmap/discussions with the |
compressHTML
doesn't remove all whitespacecompressHTML
doesn't remove all whitespace
Yeah, that makes sense to me. Thanks for the quick response Edit: created discussion withastro/roadmap#868 |
Worth also noting that the prettier plugin will sometimes forcibly insert meaningful whitespace, by breaking up long lines. (If there was a way to trim whitespace, it wouldn't be an issue) |
Thanks for the discussion here! Would be happy if someone wanted to make a PR to adjust the wording per Erika's note that
The change must be made here (in the main astro repo): And maybe update the content to something like:
|
Astro Info
Describe the Bug
Newlines are left as real whitespace in the HTML output, instead of being removed.
Input
results in this output:
which looks like "A B C" when rendered (instead of "ABC").
The documentation says:
It looks like this behavior might have changed in withastro/astro#7556 / compiler#816?
What's the expected result?
All whitespace should be collapsed, like the documentation says.
e.g. this should be the output:
If real whitespace is desired, it can always be manually added using
{" "}
. This makes the behavior more predictable.If the current behavior is intentional, then it should be documented correctly.
I can also see valid uses for both scenarios. Maybe there should be a third mode for
compressHTML
? Or an option similar tohtml-minifier
's "Collapse whitespace" and "Collapse inline tag whitespace"Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-zwd8ub?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: