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

Multiple space → nbsp translation has poor line wrapping behavior #748

Open
andersk opened this issue Oct 22, 2020 · 4 comments
Open

Multiple space → nbsp translation has poor line wrapping behavior #748

andersk opened this issue Oct 22, 2020 · 4 comments

Comments

@andersk
Copy link

andersk commented Oct 22, 2020

mobiledoc-kit currently renders multiple consecutive spaces by replacing each space-space pair with space-nbsp (#209). Depending on the text width, this results in the left margin being misaligned when a line is wrapped at that point. Emphasizing nbsp with _ to illustrate the problem:

This is a sentence that is followed by two
spaces. _This is a sentence that is followed
by three spaces. _ This is another sentence.

This is a sentence that is
followed by two spaces.
_This is a sentence that is
followed by three spaces.
_ This is another sentence.

To fix this, it would be better to replace each sequence of n spaces with n − 1 nbsps followed by 1 space. This can be done with regexp lookahead:

text.replace(/ (?= )/g, "\u00A0")
This is a sentence that is followed by two
spaces._ This is a sentence that is followed
by three spaces.__ This is another sentence.

This is a sentence that is
followed by two spaces._
This is a sentence that is
followed by three spaces.__
This is another sentence.

It might be better to disable the nbsp translation entirely and rely on CSS white-space: pre-wrap, but that’d be a bigger change.

(The same issue is present in other repositories like mobiledoc-dom-renderer, mobiledoc-html-renderer, mobiledoc-apple-news-renderer; I assume I don’t need to file separate issues for each one.)

@gpoitch
Copy link
Member

gpoitch commented Aug 31, 2022

I believe this was fixed somewhere along the way. Can't reproduce in the demo.

@gpoitch gpoitch closed this as completed Aug 31, 2022
@andersk
Copy link
Author

andersk commented Aug 31, 2022

@gpoitch
Copy link
Member

gpoitch commented Aug 31, 2022

Looks good in my browser
Screen Shot 2022-08-31 at 2 44 07 PM

@gpoitch gpoitch reopened this Aug 31, 2022
@andersk
Copy link
Author

andersk commented Aug 31, 2022

Yeah, looks like WebKit handles the wrapping differently. Try it in Chromium or Firefox.

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