osmcha-frontend
osmcha-frontend copied to clipboard
Keep line breaks intact on DISCUSSIONS tab
When typing a comment that has both right-to-left and left-to-right text (e.g. Persian comment with some English words) we put each English word or phrase in a separate line as a workaround so we wouldn't face with bidirectional problems in reading the comment (more info).
For example this is a comment on osm.org and reading it has no difficulty, because of those line breaks that separate RTL text from LTR text.

The problem is that OSMCha removes those line breaks and makes it hard to read the Persian comment.

Thanks for your feedback @iriman ! I'll look into it soon.
I recently fixed bidirectional text in discussions in osm.org. I think OSMCha should copy the formatting used by the OSM website. The formatting is extremely simple and done by this method:
- Two or more consecutive line breaks separate paragraphs from each other. Each paragraph is
<p dir="auto">. - A single line break is converted into
<br />
The actual implementation in the OSM website seems to be:
- Escape any HTML
- Format as described above
- Convert URLs to clickable links
The actual code is:
def to_html
linkify(simple_format(ERB::Util.html_escape(self)))
end
linkify and html_escape probably do what they say - convert URLs to links and escape HTML. I haven't checked them myself.
simple_format is:
def simple_format(text)
SimpleFormat.new.simple_format(text, :dir => "auto")
end
Which uses the method documented here: https://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
So you should just implement the same behavior in OSMCha for consistency with the OSM website.
Thanks for the implementation tips; this is really helpful. I know that this issue has been open for quite a while but I hadn't been aware of it until now. I will try to look into addressing this (and other issues with RTL text rendering) soon.
@jake-low happy to help :)
New development: linkify should set dir="auto" (or dir="ltr" since it's always going to start with ASCII letters anyway) on each link. I explain why in this comment: https://github.com/openstreetmap/openstreetmap-website/pull/5840#discussion_r2017676461
The pull request to do this on osm.org (the one in that link) is not accepted yet but I'm optimistic that it will be merged quite soon. And either way, OSMCha can adopt this behavior independently.