Skip to content
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

Add RTL support #13338

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Contributors
* Alastair Houghton -- Apple Help builder
* Alex Gaynor -- linkcheck retry on errors
* Alexander Todorov -- inheritance_diagram tests and improvements
* Alireza Shabani -- RTL support
* Andi Albrecht -- agogo theme
* Antonio Valentino -- qthelp builder, docstring inheritance
* Antti Kaihola -- doctest extension (skipif option)
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Features added
* #13326: Remove hardcoding from handling :class:`~sphinx.addnodes.productionlist`
nodes in all writers, to improve flexibility.
Patch by Adam Turner.
* #10385: Add RTL (right-to-left) support for all Sphinx themes via the ``is_rtl``
theme option. Includes automatic layout mirroring, and bidirectional text support.
Patch by Alireza Shabani.

Bugs fixed
----------
Expand Down
12 changes: 12 additions & 0 deletions doc/usage/theming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ These themes are:

.. versionadded:: 3.2

- **is_rtl** (true or false): Enable right-to-left (RTL) text direction.
Use this for languages that are read right-to-left (like Farsi, Arabic,
Hebrew, etc). When enabled, the theme will:

- Change text direction to RTL
- Mirror layout components
- Keep code blocks in LTR direction

Defaults to ``False``.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A version added block would be a nice addition

.. versionadded:: 8.2.0

**alabaster**
`Alabaster theme`_ is a modified "Kr" Sphinx theme from @kennethreitz
(especially as used in his Requests project), which was itself originally
Expand Down
2 changes: 2 additions & 0 deletions sphinx/themes/agogo/static/agogo.css.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* Sphinx stylesheet -- agogo theme.
*/

@import url("rtl.css");

* {
margin: 0px;
padding: 0px;
Expand Down
151 changes: 151 additions & 0 deletions sphinx/themes/agogo/static/rtl.css.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{% if theme_is_rtl|tobool %}

/* Core RTL overrides for Agogo theme */
body {
direction: rtl !important;
text-align: right !important;
}

/* Header adjustments */
div.header .headertitle {
text-align: right !important;
letter-spacing: 0 !important;
}

div.header div.rel {
direction: rtl !important;
}

p.logo {
float: left !important;
}

/* Content layout */
div.document {
float: right !important;
}

div.body {
{%- if theme_rightsidebar|tobool %}
padding-left: 2em !important;
padding-right: 0 !important;
{%- else %}
padding-right: 2em !important;
padding-left: 0 !important;
{% endif %}
}

/* Sidebar positioning */
div.sidebar,
aside.sidebar {
{%- if theme_rightsidebar|tobool %}
float: left !important;
{%- else %}
float: right !important;
{% endif %}
}

/* Lists and margins */
div.document ul {
margin-right: 1.5em !important;
margin-left: 0 !important;
}

div.document dd {
margin-right: 1.2em !important;
margin-left: 0 !important;
}

/* Admonitions */
div.admonition {
border-right: 0.2em solid black !important;
border-left: none !important;
}

/* Search elements */
ul.search {
margin: 10px 20px 0 0 !important;
}

ul.search li {
padding: 5px 20px 5px 0 !important;
background-position: right 7px !important;
}

/* Table alignments */
table.indextable td {
text-align: right !important;
}

/* Footer adjustments */
div.footer .right {
text-align: left !important;
}

div.footer .left {
text-align: right !important;
}

/* Code blocks - keep LTR */
div.highlight pre {
direction: ltr !important;
text-align: left !important;
}

/* Header links */
a.headerlink {
padding-right: .3em !important;
padding-left: 0 !important;
}

/* Sidebar list adjustments */
div.sidebar li.toctree-l1 a,
aside.sidebar li.toctree-l1 a {
padding-right: 3px !important;
padding-left: 0 !important;
}

div.sidebar li.toctree-l2 a,
aside.sidebar li.toctree-l2 a {
margin-right: 1em !important;
margin-left: 0 !important;
}

div.sidebar li.toctree-l3 a,
aside.sidebar li.toctree-l3 a {
margin-right: 2em !important;
margin-left: 0 !important;
}

/* Float adjustments */
.left {
float: right !important;
}

.right {
float: left !important;
}

/* Image alignments */
img.align-left, .figure.align-left, object.align-left {
float: right !important;
margin-left: 1em !important;
margin-right: 0 !important;
}

img.align-right, .figure.align-right, object.align-right {
float: left !important;
margin-right: 1em !important;
margin-left: 0 !important;
}

/* Viewcode extension */
.viewcode-link, .viewcode-back {
float: left !important;
}

/* Equation numbers */
span.eqno {
float: left !important;
}
{% endif %}
2 changes: 2 additions & 0 deletions sphinx/themes/basic/static/basic.css.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/* -- main layout ----------------------------------------------------------- */

@import url("rtl.css");

div.clearer {
clear: both;
}
Expand Down
1 change: 1 addition & 0 deletions sphinx/themes/basic/static/documentation_options.js.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ const DOCUMENTATION_OPTIONS = {
NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
SHOW_SEARCH_SUMMARY: {{ 'true' if show_search_summary else 'false' }},
ENABLE_SEARCH_SHORTCUTS: {{ 'true' if theme_enable_search_shortcuts|tobool else 'false'}},
IS_RTL: {{ 'true' if is_rtl else 'false' }},
};
Loading