-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: Add Right-to-Left (RTL) layout support #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ssuvamm
wants to merge
1
commit into
docsifyjs:develop
Choose a base branch
from
ssuvamm:feat/rtl-support
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+89
−0
Conversation
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
This commit introduces a new feature enabling Right-to-Left (RTL) layout for docsify sites. Key changes: - **Configuration:** Added a new boolean option `rtl` (default: `false`) to `window.$docsify` configuration in `src/core/config.js`. Setting this to `true` enables RTL mode. - **Styling:** - Created `src/themes/shared/_rtl.css` with specific styles for RTL layout, including adjustments for text direction, sidebar positioning, and content margins. - Imported `_rtl.css` into `src/themes/shared/__index.css`. - **Behavior:** Modified `src/core/Docsify.js` to add a `rtl` class to the `<body>` element when `config.rtl` is true. This class activates the RTL-specific CSS rules. - **Testing:** Added a new end-to-end test suite in `test/e2e/rtl.test.js` to verify: - The `rtl` class is applied to the body. - The sidebar is positioned on the right. - Content margins are adjusted for the right-hand sidebar. - **Documentation:** Updated `docs/configuration.md` to document the new `rtl` option, its type, default value, and usage. This feature addresses your request for better RTL support, allowing you to create documentation sites that cater to RTL languages.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
rrickay
reviewed
Jun 10, 2025
@@ -25,6 +25,11 @@ export class Docsify extends Fetch( | |||
this.initRender(); // Render base DOM | |||
this.initEvent(); // Bind events | |||
this.initFetch(); // Fetch data | |||
|
|||
if (this.config.rtl) { | |||
document.body.classList.add('rtl'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a class, what about using the dir
attribute?
<html dir="rtl">
and target the changes in the layout using that as the selector? [dir=rtl] .layout
padipiee
approved these changes
Jul 11, 2025
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
This commit introduces a new feature enabling Right-to-Left (RTL) layout for docsify sites.
Related issue, if any:
Close #2511
What kind of change does this PR introduce?
rtl
(default:false
) towindow.$docsify
configuration insrc/core/config.js
. Setting this totrue
enables RTL mode.src/themes/shared/_rtl.css
with specific styles for RTL layout, including adjustments for text direction, sidebar positioning, and content margins._rtl.css
intosrc/themes/shared/__index.css
.src/core/Docsify.js
to add artl
class to the<body>
element whenconfig.rtl
is true. This class activates the RTL-specific CSS rules.test/e2e/rtl.test.js
to verify:rtl
class is applied to the body.docs/configuration.md
to document the newrtl
option, its type, default value, and usage.For any code change,
Does this PR introduce a breaking change?
No
Tested in the following browsers: