Skip to content

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
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ssuvamm
Copy link

@ssuvamm ssuvamm commented May 27, 2025

Summary

This commit introduces a new feature enabling Right-to-Left (RTL) layout for docsify sites.

Related issue, if any:

#2511

What kind of change does this PR introduce?

  • 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.

For any code change,

  • [x ] Related documentation has been updated, if needed
  • [ x] Related tests have been added or updated, if needed

Does this PR introduce a breaking change?

No

Tested in the following browsers:

  • [x ] Chrome
  • Firefox
  • Safari
  • [x ] Edge

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.
Copy link

vercel bot commented May 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docsify-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 4:49am

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.

1 participant