Whitespace processing #1873
Replies: 4 comments 3 replies
-
I just read the suggested article "How whitespace is handled by HTML, CSS, and in the DOM", and their approach looks pretty clear and straightforward to me. I think it's a good idea to follow it. I'm concerned about how to define which tags are inline and which are block. There could be a lot of custom tags from different frameworks or custom web components, and it could be difficult to determine which are inline and which are block. |
Beta Was this translation helpful? Give feedback.
-
I'm also considering completely disabling whitespace processing in js macros, since it's not needed there at all. |
Beta Was this translation helpful? Give feedback.
-
The whitespace processing in messages is the big balck box in lingui. When i originally started working on the project the
normalizeWhitespaces
function was even not covered by tests directly. So there no a specific spec how this should work actually.In general what we have now it seems works, but there are sometimes cases which processed incorrectly by this normalizing.
I originally thought that processing is not needed at all and the safest way would be just leave string as it is. Yes, the message in catalog would not be so tidy as now, but at least this will resolve all kind of problems and mismatched related to whitespaces.
But that will not work with experimental-extractor (#1797) the esbuild re-print the AST, so original formatting is not preserved and it means runtime message would mismatch to what extracted to catalog.
By the way, esbuild when re-printing doing it safe (or lossless), so the final html result on the page would not be changed. So why we could not implement similar rules for whitespace normalizing to make it follow some spec?
I've found detailed whitespace explanation here https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Whitespace#how_does_css_process_whitespace
And I think we can implement exactly the same logic as described for non-block context.
The current whitespace normalization is a bit diffrent:
And here are examples:
in example above it has a broken message
have{count,
It is also broken in this example:
What do you think? Do you have other ideas how to make this whitespace trimming mechanism more safe and stable?
Related Issues:
#1799
#1797
#1834
Beta Was this translation helpful? Give feedback.
All reactions