Fix reading view direction for right-to-left articles - #909
Open
a-y-ibrahim wants to merge 1 commit into
Open
Conversation
The reader kept the default LTR direction for RTL articles (Arabic, Persian, Hebrew, and others) that declare a language but no explicit dir, and the standalone reader page and in-reader navigation never carried the source direction at all. Thread the article language (from Defuddle) through ReaderContent and resolve direction in one shared helper, applyReaderDirection, used by the live page, the standalone reader page, and in-reader navigation: honor an explicit source dir, else derive rtl from the language via the existing isRTLLanguage helper, else clear it. No CSS changes. Add tests for isRTLLanguage and applyReaderDirection. Closes obsidianmd#864
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
The reading view stayed left-aligned for right-to-left articles (Arabic, Persian, Hebrew, and others), which makes them hard to read. This derives the reader's text direction from the article so RTL pages mirror correctly. Closes #864.
Root cause
Reader.apply()only re-applied adirthat the source<html>already carried. Many RTL pages declarelangbut omit an explicitdir, so the reader kept the default LTR direction. The standalonereader.htmland in-reader navigation paths never carried the source direction at all, since there<html>belongs toreader.html(lang="en"), not to the article.Changes
Defuddle already reports the article language (
result.language). This threads it throughReaderContentand centralizes direction in one helper,applyReaderDirection, shared by all three reader paths (live page, standalone reader page, in-reader navigation). Resolution order: honor an explicit sourcedirif present, otherwise derivertlfrom the language via the existingisRTLLanguage()helper, otherwise clear any stale direction.Design notes
dir="auto".autoinfers base direction from the first strong character, so an Arabic paragraph starting with a Latin word (for example "Google هي شركة ...") would flip to LTR. Deriving from the language avoids that. Inline mixed runs are still handled by the browser bidi algorithm.padding-inline-*,text-align: start), so settingdirmirrors alignment.diris always respected and never overridden.Tests
Added
i18n.test.ts(isRTLLanguage) andreader.test.ts(applyReaderDirection: RTL languages and region subtags, LTR untouched, explicitdirprecedence, stale reset on navigation).Known limitation
A page declaring neither a language nor a
dir, and whose language cannot be detected, still renders LTR (no signal to infer direction). Unchanged from current behavior and out of scope here.