Skip to content

Automatic RTL/LTR per document #3569

Open

Description

@flikier

Describe your feature request

Create a new option, that will make documents to be shown with text direction RTL or LTR automatically. meaning in Editor -> Misc, to have an extra option:

  • Detect automatically document text direction

This option would override the current global setting that determines the direction of all documents.

I'm not sure how this "automatically" should happen, and I'd like to brainstorm with you. 2 Options I'm thinking of:

  1. Documents with ".rtl.md" prefix - will be detected as RTL (similar to https://github.com/dalirnet/rtl-markdown)
  2. Documents that contains RTL character in the file name - will be detected as RTL.

I'm in favor of the second option, as it's cleaner and simpler for RTL users (No need for extra typing when creating a new document, and anyway a document in an RTL language would almost certainly will have an RTL title).

Moreover, both options could be implement - So if a user wants to have an LTR title for an RTL document, s/he could add the ".rtl" to the prefix to force it, but if the title is already in RTL nothing has to be done.

What problem does this feature solve? [optional]

RTL users usually write LTR documents too, and have a mix of them in the notes library. It's a burden for them in every document opening to set again the text direction, when the app could probably deduct the direction automatically.

Additional context [optional]

I'm willing to implement it if the maintainers would agree on the feature.

Activity

  1. shayanoh commented on Sep 18, 2026

    @shayanoh

    Design/implementation notes for what's in #4804 (branch proper-rtl-support) which can close this issue:

    Storage format

    Direction is stored as an explicit <div dir="rtl">…</div> / <div dir="ltr">…</div> wrapper in the markdown source itself — a standard CommonMark HTML block, not custom front-matter or a MarkText-specific syntax. That keeps files portable: they render correctly (or at least degrade gracefully) in any other CommonMark-compliant tool, and the wrapper round-trips cleanly through markdownToState / stateToMarkdown.

    • A wrapper around the entire document body sets the document's default direction.
    • A wrapper around a single block (paragraph, heading, list item, etc.) overrides direction for just that block, nested inside the document-level wrapper if one exists.

    This is not automatic content-based detection (no scanning for Unicode RTL ranges to guess direction) — direction is explicit and user-set at both document and block granularity. That distinguishes it from #1919 (auto-detect based on content); happy to see that layered on top of this later as a heuristic that decides the wrapper for you, since the storage format wouldn't need to change.

    Editor internals

    Added a new Muya block type, direction-block (packages/muya/src/block/commonMark/directionBlock), which wraps exactly one child block and carries the dir attribute. A block only becomes a direction-block when its direction actually diverges from the inherited/document default — LTR-only documents emit no extra markup at all, so there's no format churn for the common case.

    UI entry points

    • Format → Paragraph → Document Direction — RTL / LTR, sets the whole-document default.
    • Format → Paragraph → Block Direction — RTL / LTR / "Follow Document" (clears the per-block override), scoped to the block the cursor is in.
    • Same three options are also available from the per-paragraph hover "+" menu (paragraphFrontMenu) for quick access without going through the menu bar, under a new "Direction" section.
    • The old global Preferences → Editor → Misc → Text direction toggle is removed and a text points the user to use the new feature.

    All new menu strings are localized across the existing locale files.

    Full diff is in #4804 if you want to look at the actual code — this comment is just the design summary you asked for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions