Skip to content

feat: add per-document and per-block RTL/LTR direction support - #4804

Open
shayanoh wants to merge 6 commits into
marktext:developfrom
shayanoh:proper-rtl-support
Open

shayanoh wants to merge 6 commits into
marktext:developfrom
shayanoh:proper-rtl-support

Conversation

@shayanoh

@shayanoh shayanoh commented Jun 30, 2026 •

Copy link
Copy Markdown

Summary

  • Adds Document Direction and Block Direction submenus to the Paragraph menu (RTL / LTR / Follow System), letting users set text direction per-document or for a selected block.
  • Serializes direction as standard HTML <div dir="..."> wrappers so .md files remain portable across other renderers.
  • Adds a new DirectionBlock container to the muya engine; markdownToState pre-processes direction wrappers before the marked lexer (handles blank lines inside code blocks); stateToMarkdown wraps the full document or individual blocks.
  • Wires a new mt::editor-direction-action IPC channel; applyDocumentDir applies the dir attribute to the DOM on load, tab switch, and source→WYSIWYG handoff.
  • Locale keys added for all 10 supported language files.

Motivation

MarkText had no way to write RTL text (Arabic, Hebrew, Persian, etc.) correctly. Users had to rely on OS-level workarounds with no per-document control.

Test plan

  • Open a new document → Paragraph → Document Direction → RTL: entire document should flip.
  • Select a paragraph → Paragraph → Block Direction → RTL: only that block flips; rest stays LTR.
  • Save the file; reopen: direction should be preserved (stored as <div dir="rtl">...</div>).
  • Open the saved .md in another renderer (e.g. GitHub preview): <div dir> wrapper visible and correct.
  • Switch between source-code mode and WYSIWYG: direction attribute persists.
  • Tab switching: direction is correctly applied when switching between open documents.
  • pnpm run lint passes.
  • pnpm run typecheck passes.

Related

Closes #1919 and probably Closes #3569 by allowing the user to set the document direction.
This Closes #5244 feature issue that was created for thi PR.
🤖 Generated with Claude Code

shayanoh and others added 2 commits June 30, 2026 21:40
Serializes direction as standard HTML <div dir="..."> wrappers so .md
files remain portable across other renderers.

- muya: new DirectionBlock container; markdownToState pre-processes
  direction wrappers before the marked lexer (handles blank lines inside
  code blocks); stateToMarkdown wraps the full document or individual
  blocks; IDirectionBlockState added to the type union
- desktop: mt::editor-direction-action IPC channel; Document Direction
  and Block Direction submenus in the Paragraph menu (RTL/LTR/Follow
  checkboxes); applyDocumentDir applies the dir attribute to the DOM on
  load, tab switch, and source→WYSIWYG handoff; listenForMain.ts forwards
  the IPC to the bus; locale keys added for all 10 language files
- fixes: empty json-change op (was null, crashing History._record); block
  direction detection when cursor is inside an existing DirectionBlock
  (getBlockDirection, setBlockDirection, unwrapDirectionBlock); IPC
  forwarding that was silently dropping direction menu actions

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@Jocs

Jocs commented Jul 5, 2026

Copy link
Copy Markdown
Member

I found all your test plan unchecked?

@shayanoh

shayanoh commented Jul 7, 2026

Copy link
Copy Markdown
Author

I found all your test plan unchecked?

I didn't know I have to check them here, I have tested it and it works. I'm using my own branch at the time and I've had no problems so far.
I updated the description to tick all the items.

@shayanoh

Copy link
Copy Markdown
Author

I've merged the latest develop branch into my pr, and tested that it still works, so it can be merged. I'd appreciate of someone review it.

@Jocs

Jocs commented Sep 4, 2026

Copy link
Copy Markdown
Member

Please fix the conficts and open a feature issue first.

@shayanoh

shayanoh commented Sep 4, 2026 •

Copy link
Copy Markdown
Author

I've fixed the conflicts, and opened feature issue #5244 .
This is a sample rtl markdown file what works with the new PR: rtl.md

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.

Automatic RTL/LTR per document Always RTL or LTR [Feature] Add proper RTL support to marktext

2 participants