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

Allow Liquid to replace   characters #859

Closed
StephenBrownski opened this issue Feb 2, 2017 · 1 comment
Closed

Allow Liquid to replace   characters #859

StephenBrownski opened this issue Feb 2, 2017 · 1 comment

Comments

@StephenBrownski
Copy link

There seems to be inconsistencies in how liquid the replace filter handles the   entity. It cannot replace a   that was in the string originally, but it can replace  s that were added via liquid.

Example:

Page with a   somewhere in the body content, with normal spaces everywhere else.

{{ page.content | replace: ' ', ' ' | replace: ' ', ' ' }} will convert all normal spaces to non-breaking spaces, and then all the new nbsps will be converted back to regular spaces. The nbsp present in the page content from the beginning will not be converted back.

A video example:
https://screenshot.click/02-39-ecwkn-j9v56.mp4

Though the above example is obviously an intentional edge case, it could definitely be very useful in cases where a user has imported a large amount of content from elsewhere. Especially since in the rte code view, you cannot distinguish between a regular space and a  . This would be useful in making sure content is consistently output.

@pushrax
Copy link
Contributor

pushrax commented Feb 10, 2017

Liquid doesn't know anything about HTML entities itself. Somewhere along the line (maybe before saving to the database),   is being converted to a UTF-8 "NO-BREAK SPACE" character, \u00A0.

Liquid does not support escaped characters in string literals, so you will need to use something that looks like {{ page.content | replace: ' ', ' ' }} where the first space is a real UTF-8 0xA0 character and the second one is a UTF-8 0x20. Note that copy/pasting from this page won't work due to something about GitHub's comment system, you'll need to generate it yourself. Here's a Ruby string you can use: puts "{{ page.content | replace: '\u00A0', ' ' }}"

@pushrax pushrax closed this as completed Feb 10, 2017
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

No branches or pull requests

2 participants