Skip to content

feat: add auto-RTL for mixed-script content in auto mode - #96

Open
alinadaf wants to merge 1 commit into
esm7:masterfrom
alinadaf:feat/auto-rtl-mixed-content
Open

feat: add auto-RTL for mixed-script content in auto mode#96
alinadaf wants to merge 1 commit into
esm7:masterfrom
alinadaf:feat/auto-rtl-mixed-content

Conversation

@alinadaf

Copy link
Copy Markdown

Summary

Adds a new setting Auto-RTL for mixed LTR/RTL content (disabled by default) that, when enabled in auto mode, overrides the browser's first-strong-character heuristics for lines containing RTL scripts.

Details

Problem

When a line starts with English text but contains Arabic, Hebrew, or Persian later (e.g. Hello سلام), the browser's dir="auto" sees the first strong character (Latin) and renders the line LTR — which is incorrect.

Solution

  • EditorPlugin.ts: Modified buildDecorations() to check each line for RTL characters when auto mode + setting enabled, applying dir="rtl" when found.
  • MarkdownPostProcessor.ts: Added applyMixedContentRTL() that applies dir="rtl" to block elements (p, li, h1-h6, td, th, blockquote) containing RTL scripts in reading view.
  • direction.util.ts: Added shared RTL_CHAR_REGEX and hasRtlChar() utility.
  • settingsTab.ts: New boolean setting autoRTLForMixedContent with UI toggle.

Testing

Set default direction to Auto, enable the new setting, and type mixed LTR/RTL content in a note.

When auto mode is active and the setting is enabled, lines containing RTL scripts (Arabic, Hebrew, Persian, etc.) are treated as RTL regardless of their first directional character.

Works in both editor (CodeMirror line decorations) and reading view (MarkdownPostProcessor). Includes a toggle in settings.
@esm7

esm7 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Hi Ali,

First, we cannot call it "auto", as "auto RTL" is the common and universal name for the "BIDI algorithm" which is exactly the default behavior: decide based on the first letter with strong directionality.

What you want is a different logic that I don't know how to call, perhaps something like "RTL-preferred auto". As it gives precedence to switching to RTL regardless of where the relevant characters are in the sentence.

However, I find this logic very uncommon and very counter-intuitive. Do you really want sentences like "I wrote a message to my friend Ali (علي), who said RTL needs to be improved" to switch to RTL? Can you explain the need, and whether you know any software that behaves like that?

@alinadaf

alinadaf commented Aug 2, 2026 via email

Copy link
Copy Markdown
Author

@esm7

esm7 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Hi Ali,

Since RTL and BIDI support is a well-established doctrine, I don't want us to make up behaviors that no app ever uses.
As far as I know, your "any RTL character wins" algorithm is uncommon and not used by any software.
Let's work to find a solution to your described use case that is within well-established norms.

For example, how about we add a syntax to a block to mark it as RTL, e.g. decide that if the block opening includes # direction: rtl, it is forced RTL?
This is much more consistent with how BIDI-compatible software behaves. Lots of software, from MS Word to web apps, usually have auto, RTL or LTR, while nothing has the logic of "RTL if some character in the middle is RTL".

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

Successfully merging this pull request may close these issues.

2 participants