Support RTL blocks for LTR-layout website and vice versa

AI-generated summary

The discussion revolves around supporting RTL (right-to-left) blocks in LTR (left-to-right) layout websites and vice versa. SafaAlfulaij expresses the need for this feature, as users may want to write both RTL and LTR text in a single post. Currently, the text direction is determined by the website’s language layout.

SafaAlfulaij tried using HTML’s dir attribute to change the text direction, but it didn’t work. simon explains that the dir attribute needs to be whitelisted and mentions that changes in the latest Discourse release affected its functionality.

As an alternative, elijah suggests using RTL and LTR marks. However, simon develops a plugin that adds bbcode tags for text-direction, allowing users to switch between RTL and LTR text using [text-direction=rtl][/text-direction] and [text-direction=ltr][/text-direction] tags.

With codinghorror’s request, eviltrout whitelists the dir attribute, making it possible to use the HTML attribute to change the text direction.

Users would like sometimes to write both RTL and LTR text in one single post.
Right now, the direction of everything in the website (including text editor and posted posts) depends on the layout of the language used. Arabic means RTL and English means LTR.
It would be helpful if one can choose that he wants these paragraphs to be opposite the direction of the website.
I tried:

<div dir="rtl">
…
</div>

to force a direction change since HTML is supported, but that didn’t do anything, even if it does on GitHub.
If the above works, then it will be enough as a first step :wink:

5 „Gefällt mir“

You need to whitelist the dir attribute. I previously had this working in a plugin, but some changes have been made to the way text is rendered in the latest Discourse release. Now in master: ES6 Modules + Text Rendering
It won’t be difficult to get it working again.

4 „Gefällt mir“

It’s a little more awkward, but don’t the RTL and LTR marks work?

Should this be white listed @eviltrout?

2 „Gefällt mir“

I’ve wanted to figure out how to work with the new text rendering setup for a while now, so I made a plugin that adds bbcode tags for text-direction. It lets you use the tags [text-direction=rtl][/text-direction] for rtl text and [text-direction=ltr][/text-direction] for ltr text.

I have only tested this lightly on my local setup, so if you use it and run into any problems, let me know. Note: this plugin will only work on the latest version of Discourse, where text rendering is using ES6 modules. If you are using an older version of Discourse, it wouldn’t be much work to convert the plugin to work for that.

Check it out here:
https://github.com/scossar/discourse-text-direction

2 „Gefällt mir“

Sure, this seems reasonable. I’ve whitelisted it:

https://github.com/discourse/discourse/commit/4d8584f427863fd3bed176808b82e38379c41147

9 „Gefällt mir“

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.