22
33from pathlib import Path
44
5- from markupsafe import Markup , escape
65from sphinx .locale import get_translation
76
87TYPE_CHECKING = False
1918MESSAGE_CATALOG_NAME = "python-docs-theme"
2019
2120
22- def _tobool (val : object ) -> bool :
23- if isinstance (val , str ):
24- return val .lower () in {"true" , "1" , "yes" , "on" }
25- return bool (val )
26-
27-
2821def add_translation_to_context (
2922 app : Sphinx ,
3023 pagename : str ,
@@ -44,40 +37,15 @@ def combined(message: str) -> str:
4437 context ["_" ] = context ["gettext" ] = context ["ngettext" ] = combined
4538
4639
47- def add_html_dir_to_context (
48- app : Sphinx ,
49- pagename : str ,
50- templatename : str ,
51- context : dict [str , Any ],
52- doctree : None ,
53- ) -> None :
54- language = app .config .language or "en"
55-
56- is_rtl_option = context .get ("theme_is_rtl" , "" )
57- if is_rtl_option in (None , "" ):
58- is_rtl = False
59- else :
60- is_rtl = _tobool (is_rtl_option )
61-
62- dir_attr = "rtl" if is_rtl else "ltr"
63-
64- content_root = context .get ("content_root" , "" )
65- lang_part = f' lang="{ escape (language )} "' if language is not None else ""
66- context ["html_tag" ] = Markup (
67- f'<html{ lang_part } dir="{ dir_attr } " data-content_root="{ escape (content_root )} ">'
68- )
69-
70-
7140def setup (app : Sphinx ) -> ExtensionMetadata :
7241 app .require_sphinx ("7.3" )
7342
7443 app .add_html_theme ("python_docs_theme" , str (THEME_PATH ))
7544 app .add_message_catalog (MESSAGE_CATALOG_NAME , LOCALE_DIR )
7645 app .connect ("html-page-context" , add_translation_to_context )
77- app .connect ("html-page-context" , add_html_dir_to_context )
7846
7947 return {
8048 "version" : __version__ ,
8149 "parallel_read_safe" : True ,
8250 "parallel_write_safe" : True ,
83- }
51+ }
0 commit comments