You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in a comment in #97@dbrgn pointed out that we're assuming that preserving whitespace and newlines doesn't matter when it actually does. The current implementation will break for white-space: pre-wrap among other scenarios.
/// FIXME: Stop doing this! Instead of inserting text nodes just check how much white space
/// is between the block and the tag before it as well as the block and the tag after it.
/// Then, insert quote! tokens that take a mutable reference to the first element in the
/// iterable nodes and adds spacing / new lines before it if it is a VText variant.
/// Then take a mutable reference to the last element in the iterable nodes and add
/// spacing after it if it is a VText variant. Add methods to IterableNodes to easily
/// get an optional reference to the first or last element.
Notably, handling braces by injecting quote'd tokens that will mutate the real text nodes allows us to stop doing this hack of injecting text nodes when we're unsure if a brace will contain a text node. We can just handle this at runtime by injecting quote'd tokens.
Hi person reading this! If you run into this issue and need this done let me know and I'll prioritize it! Otherwise I'll get to it whenever I get to it (aka when it becomes a problem for me).
The text was updated successfully, but these errors were encountered:
Given that - going to instead just require that in the rare cases that someone wants to preserve exact sequences of whitespace (instead of the usual collapsing into one whitespace) they can just use text variable interpolation.
fnmain(){let text = r#"This needsit's whitespace perfectly preserved"#;html!{ <span style="white-space: pre-wrap">{ text }</span> };}
So going to add documentation on this then close this issue.
in a comment in #97 @dbrgn pointed out that we're assuming that preserving whitespace and newlines doesn't matter when it actually does. The current implementation will break for
white-space: pre-wrap
among other scenarios.Here's how we need to handle braces
percy/crates/html-macro/src/parser/mod.rs
Lines 196 to 202 in 95a53a8
Notably, handling braces by injecting quote'd tokens that will mutate the real text nodes allows us to stop doing this hack of injecting text nodes when we're unsure if a brace will contain a text node. We can just handle this at runtime by injecting quote'd tokens.
percy/crates/html-macro-test/src/lib.rs
Line 164 in 683bbda
And for text tokens we can preserve whitespace by finding the line / column differences between neighboring text token trees here
percy/crates/html-macro/src/tag.rs
Lines 244 to 255 in 344e757
Then later when parsing text we can look at the tag that comes before and after the text to determine how much more space to put around it
https://github.com/chinedufn/percy/blob/edd4122ccee157566e5118e4c3e74d210eb3a091/crates/html-macro/src/parser/text.rs#L5-L4
As always... unit testing will be paramount here. Need to add cases one by one and make them pass.
https://github.com/chinedufn/percy/blob/e124a87e2c119d760e2e1cfdd3ace0e64945ba93/crates/html-macro-test/src/text.rs#L2-L1
Hi person reading this! If you run into this issue and need this done let me know and I'll prioritize it! Otherwise I'll get to it whenever I get to it (aka when it becomes a problem for me).
The text was updated successfully, but these errors were encountered: