Skip to content

fix: export PDF/HTML/print in the editor's text direction (RTL) - #4678

Merged
Jocs merged 2 commits into
developfrom
fix/rtl-pdf-export
Jun 24, 2026
Merged

Jocs merged 2 commits into
developfrom
fix/rtl-pdf-export

Conversation

@Jocs

@Jocs Jocs commented Jun 24, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #4553 — documents authored in Right-to-Left (RTL) mode were exported as PDF (and styled-HTML / print) in left-to-right. The exported page ignored the editor's text-direction setting entirely.

Root cause

The export pipeline never carried the text direction:

  • The engine shell (@muyajs/core MarkdownToHtml.generate) hard-codes <html lang="en"> with no dir.
  • The desktop wrapper exportStyledHTML never received or forwarded the editor's textDirection.

So regardless of Preferences → Editor → Text direction = Right to left, every export rendered LTR.

Fix

  1. Engine (markdownToHtml.ts): generate(options) gains an optional dir. It emits dir="rtl" / dir="auto" on the root <html>; ltr is the HTML default and stays implicit, so existing LTR exports are byte-identical.
  2. Desktop (exportHtml.ts, editor.vue): thread textDirection ('ltr' | 'rtl' | 'auto') from the editor through exportStyledHTML into generate({ dir }) for the pdf, styledHtml, and print export paths. The hand-written @muyajs/core ambient declaration is widened to match.

dir="rtl" on <html> cascades to the .markdown-body article, so paragraphs flow right-to-left and text aligns right in the exported PDF.

Tests

  • packages/muya/.../exportHtmlDir.spec.ts — engine emits dir="rtl"/"auto", omits it for LTR.
  • packages/desktop/.../exportHtml.spec.ts — the desktop wrapper forwards dir through the real engine end-to-end.
  • pnpm run typecheck, muya + desktop lint, and the existing export regression suites pass.

Verification

Rendered the exact export shell (<html lang="en" dir="rtl"> + .markdown-body) in the Electron 42 Chromium binary: getComputedStyle(body).direction === 'rtl', the paragraph's right edge hugs the article's right edge (RTL flow), and nested list items inset from the right.

🤖 Generated with Claude Code

Jocs and others added 2 commits June 24, 2026 20:27
Add an optional `dir` to `generate(options)` that sets the attribute on the
exported document's root `<html>`. `rtl` / `auto` are emitted; `ltr` is the
HTML default and stays implicit so existing LTR exports are byte-identical.

Enables RTL-correct standalone HTML / PDF / print export (#4553).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The styled-export wrapper never carried the editor's text direction, so RTL
documents always exported left-to-right (#4553). Thread `textDirection` from
the editor through `exportStyledHTML` into the engine's `generate({ dir })`
for the pdf, styledHtml, and print paths, and widen the hand-written
`@muyajs/core` `generate` declaration to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

Build artifacts for PR #4678:

Run: https://github.com/marktext/marktext/actions/runs/28098543758

Artifact Size Link
marktext-windows-arm64 275.6 MB Download
marktext-macos-x64 292.9 MB Download
marktext-linux 627.2 MB Download
marktext-windows-x64 283.8 MB Download
marktext-macos-arm64 282.6 MB Download

@Jocs
Jocs merged commit 9908253 into develop Jun 24, 2026
16 of 17 checks passed
@Jocs
Jocs deleted the fix/rtl-pdf-export branch June 24, 2026 15:37
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.

[Bug] RTL PDF Export

1 participant