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

Keeping whitespaces for text nodes #23

Merged
merged 1 commit into from
May 11, 2023

Conversation

bennyboer
Copy link
Contributor

Regarding issue #22

I was fiddling a little with pest to fix this problem. Unfortunately there is no easy fix as the problem occurs when using implicit whitespaces. We can avoid the problem by using atomic rules. Unfortunately the rules we'd need to make atomic are also silent and there is no solution for atomic and silent rules yet (see pest-parser/pest#520). There is also a discussion changing whitespace handling alltogether where some people recommended just not relying on implicit whitespaces and rather doing is explicitely. With this PR I tried to do that and added some tests to verify the whitespace parsing behavior.

  • Removed WHITESPACE rule to avoid pests implicit whitespace handling
  • Instead using the WSP rule explicitely where is makes sense

Tests are all green, so I am pretty confident that everything works as expected. Unfortunately I am a pest newbie. Therfore if you could review the rewritten grammar that would be pretty great!

Thanks!

<div > Text </div>

<!-- Whitespaces in closing tag to the left (should not work) -->
<div> Text < /div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases where </ is separated by a whitespace like < / do not work in browsers as well, so I just didn't make them work either

@@ -62,7 +62,7 @@ expression: dom
],
"children": [
"this is deep",
"hello world"
"hello world\n "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some cases where we get this ugly output. But this seems to be the same thing browsers do when you try to edit text nodes where they also seem to include line breaks and stuff.

Altogether I think this is the better behavior as you can just trim the result if you don't need the whitespaces.

Copy link

@xkr47 xkr47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes for whitespace parsing

src/dom/mod.rs Show resolved Hide resolved
src/dom/mod.rs Show resolved Hide resolved
@mathiversen mathiversen changed the base branch from master to dev May 11, 2023 21:08
@mathiversen mathiversen merged commit f09a1cb into mathiversen:dev May 11, 2023
@xkr47
Copy link

xkr47 commented Jun 3, 2023

Come on @mathiversen you marked my review comments as resolved without further comments?

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

Successfully merging this pull request may close these issues.

None yet

3 participants