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

1 participant