Repository navigation
fix: export PDF/HTML/print in the editor's text direction (RTL) - #4678
Merged
Merged
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
@muyajs/coreMarkdownToHtml.generate) hard-codes<html lang="en">with nodir.exportStyledHTMLnever received or forwarded the editor'stextDirection.So regardless of
Preferences → Editor → Text direction = Right to left, every export rendered LTR.Fix
markdownToHtml.ts):generate(options)gains an optionaldir. It emitsdir="rtl"/dir="auto"on the root<html>;ltris the HTML default and stays implicit, so existing LTR exports are byte-identical.exportHtml.ts,editor.vue): threadtextDirection('ltr' | 'rtl' | 'auto') from the editor throughexportStyledHTMLintogenerate({ dir })for thepdf,styledHtml, andprintexport paths. The hand-written@muyajs/coreambient declaration is widened to match.dir="rtl"on<html>cascades to the.markdown-bodyarticle, so paragraphs flow right-to-left and text aligns right in the exported PDF.Tests
packages/muya/.../exportHtmlDir.spec.ts— engine emitsdir="rtl"/"auto", omits it for LTR.packages/desktop/.../exportHtml.spec.ts— the desktop wrapper forwardsdirthrough 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