osmcha-frontend icon indicating copy to clipboard operation
osmcha-frontend copied to clipboard

Keep line breaks intact on DISCUSSIONS tab

Open iriman opened this issue 6 years ago • 4 comments

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.

Comment on osm.org

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

Comment on OSMCha

iriman avatar Jul 10 '19 16:07 iriman

Thanks for your feedback @iriman ! I'll look into it soon.

willemarcel avatar Jul 24 '19 15:07 willemarcel

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:

  1. Two or more consecutive line breaks separate paragraphs from each other. Each paragraph is <p dir="auto">.
  2. A single line break is converted into <br />

The actual implementation in the OSM website seems to be:

  1. Escape any HTML
  2. Format as described above
  3. Convert URLs to clickable links

The actual code is:

    def to_html
      linkify(simple_format(ERB::Util.html_escape(self)))
    end

(permalink)

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

(permalink)

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.

NeatNit avatar Mar 24 '25 23:03 NeatNit

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 avatar Mar 25 '25 00:03 jake-low

@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.

NeatNit avatar Apr 03 '25 16:04 NeatNit