mkdocs-toggle-sidebar-plugin 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. {mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin.egg-info → mkdocs_toggle_sidebar_plugin-0.0.6}/PKG-INFO +82 -13
  2. mkdocs_toggle_sidebar_plugin-0.0.6/README.md +181 -0
  3. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/setup.cfg +5 -3
  4. mkdocs_toggle_sidebar_plugin-0.0.6/src/mkdocs_toggle_sidebar_plugin/__init__.py +135 -0
  5. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin/material.js +20 -14
  6. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js +17 -4
  7. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6/src/mkdocs_toggle_sidebar_plugin.egg-info}/PKG-INFO +82 -13
  8. mkdocs_toggle_sidebar_plugin-0.0.6/src/mkdocs_toggle_sidebar_plugin.egg-info/requires.txt +1 -0
  9. mkdocs_toggle_sidebar_plugin-0.0.4/README.md +0 -115
  10. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin/__init__.py +0 -73
  11. mkdocs_toggle_sidebar_plugin-0.0.4/src/mkdocs_toggle_sidebar_plugin.egg-info/requires.txt +0 -1
  12. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/LICENSE +0 -0
  13. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/MANIFEST.in +0 -0
  14. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/pyproject.toml +0 -0
  15. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin/mkdocs.js +0 -0
  16. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin/readthedocs.js +0 -0
  17. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin.egg-info/SOURCES.txt +0 -0
  18. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin.egg-info/dependency_links.txt +0 -0
  19. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin.egg-info/entry_points.txt +0 -0
  20. {mkdocs_toggle_sidebar_plugin-0.0.4 → mkdocs_toggle_sidebar_plugin-0.0.6}/src/mkdocs_toggle_sidebar_plugin.egg-info/top_level.txt +0 -0
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mkdocs-toggle-sidebar-plugin
3
- Version: 0.0.4
4
- Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
3
+ Version: 0.0.6
4
+ Summary: Add keybindings to toggle the navigation and table of contents sidebars
5
5
  Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
6
  Author: six-two
7
7
  Author-email: pip@six-two.dev
@@ -12,10 +12,13 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
15
17
  Requires-Python: >=3.9
16
18
  Description-Content-Type: text/markdown
17
19
  License-File: LICENSE
18
- Requires-Dist: mkdocs>=1.4.0
20
+ Requires-Dist: mkdocs>=1.5.0
21
+ Dynamic: license-file
19
22
 
20
23
  # mkdocs-toggle-sidebar-plugin
21
24
 
@@ -64,7 +67,41 @@ Key | Action
64
67
  For some themes like `readthedocs` navigation and TOC are combined.
65
68
  In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
66
69
 
67
- ### Toggle button
70
+ ### Configuration options
71
+
72
+ You can overwrite the defaults like this:
73
+
74
+ ```yaml
75
+ plugins:
76
+ - search
77
+ - toggle-sidebar:
78
+ async: False
79
+ debug: True
80
+ enabled: True
81
+ inline: False
82
+ javascript: ./toggle-sidebar.js
83
+ show_navigation_by_default: False
84
+ show_toc_by_default: False
85
+ theme: material
86
+ toggle_button: all
87
+ ```
88
+
89
+ The following options exist:
90
+
91
+ Option | Type | Default value | Description
92
+ --- | ---| --- | ---
93
+ async | `bool` | `False` | Asynchronously load the JavaScript file created by the plugin
94
+ debug | `bool` | `False` | Show some debug messages during mkdocs build (for example related to theme detection)
95
+ enabled | `bool` | `True` | Can be used to disable the plugin. Usually used in combination with environment variables like `enabled: !ENV [TOGGLE_SIDEBAR, false]` as described in [mkdocs's docs](https://www.mkdocs.org/user-guide/configuration/#enabled-option)
96
+ inline | `bool` | `True` | Instead of storing the javascript code in the file specified by `javascript`, it is directly copied into each page. Slightly increases page size, but can improve load times a little bit and reduce flickering on page (re-)load
97
+ javascript | `str` | `"assets/javascripts/toggle-sidebar.js"` | The path where to store the output file
98
+ show_navigation_by_default | `bool` | `True` | Whether to show the navigation by default
99
+ show_toc_by_default | `bool` | `True` | Whether to show the table of contents by default
100
+ theme | `str` | `auto` | Used for theme detection. With `auto`, the plugin tries to automatically detect the theme. But you can also force it to use a specific theme preset that you know will work. Currently supported values: `material`/`ansible`, `mkdocs`, `readthedocs`.
101
+ toggle_button | `str` | `"none"` | Can be set to show a toggle button (see below)
102
+
103
+
104
+ #### Toggle button
68
105
 
69
106
  When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
70
107
  It is usually in the nav or the top bar.
@@ -90,35 +127,67 @@ The names and parameters should be self-explanatory.
90
127
  ## Theme support
91
128
 
92
129
  Below shows the latest themes that I have tested.
93
- They are not updated that often, and the plugin should generally work for other of theme versions too.
130
+ The table is not updated regularly, but the plugin should generally work for other theme versions too.
94
131
 
95
132
  Theme | Theme version | Plugin version | Status
96
133
  --- | --- | --- | ---
97
- mkdocs-material | 9.5.34 | 0.0.4 | works
98
- mkdocs (default) | 1.6.1 | 0.0.4 | works
99
- readthedocs | 1.6.1 | 0.0.4 | works
134
+ mkdocs-ansible | 25.6.0 | 0.0.6 | works
135
+ mkdocs-material | 9.6.14 | 0.0.4+ | works
136
+ mkdocs (default) | 1.6.1 | 0.0.4+ | works
137
+ readthedocs | 1.6.1 | 0.0.4+ | works
100
138
 
101
- Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
139
+ Just open an issue / PR if you use a strange theme or the info above is not up-to-date anymore.
102
140
 
103
141
  ### Note to self
104
142
 
105
- Test mkdocs-material theme:
143
+ Test `material` theme:
106
144
  ```bash
107
145
  ./serve.sh
108
146
  ```
109
147
 
110
- Test mkdocs theme:
148
+ Test `mkdocs` theme:
111
149
  ```bash
112
150
  ./serve.sh --theme mkdocs
113
151
  ```
114
152
 
153
+ Test `mkdocs`, `readthedocs` and `material` themes:
154
+ ```bash
155
+ ./build.sh
156
+ python3 -m http.server --directory './public/'
157
+ ```
158
+
159
+ Test oldest python version supported by me (3.9):
160
+ ```bash
161
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:3.9 ./serve.sh
162
+ ```
163
+
164
+ Test newest available python version (currently 3.13):
165
+ ```bash
166
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:latest ./serve.sh
167
+ ```
168
+
169
+
115
170
  ## Notable changes
116
171
 
172
+ ### Version 0.0.6
173
+
174
+ - Fixed toggle button appearing delayed on slow loading pages (see #6)
175
+ - Fixed behavior when using Material's `navigation.instant` feature (see #5)
176
+ - Added `inline` option that prevents page flickering on reload (see #4). It is now enabled by default and async is disabled by default, to prevent the flickering. To revert to the old behavior you can set `async: True` and `inline: False` in the plugin's config in your `mkdocs.yml`
177
+ - Added `theme` option that allows you to override theme detection (see #3)
178
+ - Added support for `ansible` theme (see #3)
179
+ - Added fallback to check `theme.extra.base_theme` from `mkdocs.yml` when other theme detection logic fails (see #3)
180
+ - Added `debug` option
181
+
182
+ ### Version 0.0.5
183
+
184
+ - Bug fix: On small screens with the material theme the navigation would be hidden, even when the hamburger menu was opened.
185
+
117
186
  ### Version 0.0.4
118
187
 
119
188
  - Export API via `MkdocsToggleSidebarPlugin` object.
120
189
  This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
121
- - Added `toggle_button` option and implemented it for Material theme
190
+ - Added `toggle_button` option and implemented it for Material theme.
122
191
 
123
192
  ### Version 0.0.3
124
193
 
@@ -0,0 +1,181 @@
1
+ # mkdocs-toggle-sidebar-plugin
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
4
+ ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
5
+ ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
6
+
7
+ This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
8
+
9
+ - [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
10
+ - Builtin themes: `mkdocs`, `readthedocs`
11
+
12
+ You can play around with it and these themes on the [test page](https://mkdocs-toggle-sidebar.six-two.dev).
13
+
14
+ The settings are stored using the `localStorage` object, so that it will persist between pages.
15
+
16
+ I wrote it after getting frustrated by the browser's `Find in page` function matching way to many links in the navigation sidebar instead of searching in the actual page's content.
17
+
18
+
19
+ ## Usage
20
+
21
+ ### Setup
22
+
23
+ First install the PyPI package:
24
+ ```bash
25
+ pip install mkdocs-toggle-sidebar-plugin
26
+ ```
27
+
28
+ Add something like the following to your `mkdocs.yml`:
29
+ ```yaml
30
+ plugins:
31
+ - search
32
+ - toggle-sidebar
33
+ ```
34
+
35
+ ### Key bindings
36
+
37
+ The plugin adds the following key bindings:
38
+
39
+ Key | Action
40
+ --- | ---
41
+ `b` | toggle **b**oth (TOC and navigation)
42
+ `m` | toggle navigation **m**enu
43
+ `t` | toggle **T**OC
44
+
45
+ For some themes like `readthedocs` navigation and TOC are combined.
46
+ In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
47
+
48
+ ### Configuration options
49
+
50
+ You can overwrite the defaults like this:
51
+
52
+ ```yaml
53
+ plugins:
54
+ - search
55
+ - toggle-sidebar:
56
+ async: False
57
+ debug: True
58
+ enabled: True
59
+ inline: False
60
+ javascript: ./toggle-sidebar.js
61
+ show_navigation_by_default: False
62
+ show_toc_by_default: False
63
+ theme: material
64
+ toggle_button: all
65
+ ```
66
+
67
+ The following options exist:
68
+
69
+ Option | Type | Default value | Description
70
+ --- | ---| --- | ---
71
+ async | `bool` | `False` | Asynchronously load the JavaScript file created by the plugin
72
+ debug | `bool` | `False` | Show some debug messages during mkdocs build (for example related to theme detection)
73
+ enabled | `bool` | `True` | Can be used to disable the plugin. Usually used in combination with environment variables like `enabled: !ENV [TOGGLE_SIDEBAR, false]` as described in [mkdocs's docs](https://www.mkdocs.org/user-guide/configuration/#enabled-option)
74
+ inline | `bool` | `True` | Instead of storing the javascript code in the file specified by `javascript`, it is directly copied into each page. Slightly increases page size, but can improve load times a little bit and reduce flickering on page (re-)load
75
+ javascript | `str` | `"assets/javascripts/toggle-sidebar.js"` | The path where to store the output file
76
+ show_navigation_by_default | `bool` | `True` | Whether to show the navigation by default
77
+ show_toc_by_default | `bool` | `True` | Whether to show the table of contents by default
78
+ theme | `str` | `auto` | Used for theme detection. With `auto`, the plugin tries to automatically detect the theme. But you can also force it to use a specific theme preset that you know will work. Currently supported values: `material`/`ansible`, `mkdocs`, `readthedocs`.
79
+ toggle_button | `str` | `"none"` | Can be set to show a toggle button (see below)
80
+
81
+
82
+ #### Toggle button
83
+
84
+ When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
85
+ It is usually in the nav or the top bar.
86
+ Clicking the button will toggle the navigation, table of contents, or both (depending on the supplied value).
87
+ By leaving the field empty or setting it to `none`, no button is added.
88
+
89
+ ### Exported API functions
90
+
91
+ This plugin exposes some JavaScript functions, that can show, hide or toggle the visibility of the sidebars.
92
+ You can see how they are called in `docs/javascript-functions.md` and how they are defined in `src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js`.
93
+
94
+ In short there are:
95
+
96
+ - `MkdocsToggleSidebarPlugin.setNavigationVisibility(show: bool)`
97
+ - `MkdocsToggleSidebarPlugin.setTocVisibility(show: bool)`
98
+ - `MkdocsToggleSidebarPlugin.setAllVisibility: (showNavigation: bool, showTOC: bool)`
99
+ - `MkdocsToggleSidebarPlugin.toggleNavigationVisibility()`
100
+ - `MkdocsToggleSidebarPlugin.toggleTocVisibility()`
101
+ - `MkdocsToggleSidebarPlugin.toggleAllVisibility()`
102
+
103
+ The names and parameters should be self-explanatory.
104
+
105
+ ## Theme support
106
+
107
+ Below shows the latest themes that I have tested.
108
+ The table is not updated regularly, but the plugin should generally work for other theme versions too.
109
+
110
+ Theme | Theme version | Plugin version | Status
111
+ --- | --- | --- | ---
112
+ mkdocs-ansible | 25.6.0 | 0.0.6 | works
113
+ mkdocs-material | 9.6.14 | 0.0.4+ | works
114
+ mkdocs (default) | 1.6.1 | 0.0.4+ | works
115
+ readthedocs | 1.6.1 | 0.0.4+ | works
116
+
117
+ Just open an issue / PR if you use a strange theme or the info above is not up-to-date anymore.
118
+
119
+ ### Note to self
120
+
121
+ Test `material` theme:
122
+ ```bash
123
+ ./serve.sh
124
+ ```
125
+
126
+ Test `mkdocs` theme:
127
+ ```bash
128
+ ./serve.sh --theme mkdocs
129
+ ```
130
+
131
+ Test `mkdocs`, `readthedocs` and `material` themes:
132
+ ```bash
133
+ ./build.sh
134
+ python3 -m http.server --directory './public/'
135
+ ```
136
+
137
+ Test oldest python version supported by me (3.9):
138
+ ```bash
139
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:3.9 ./serve.sh
140
+ ```
141
+
142
+ Test newest available python version (currently 3.13):
143
+ ```bash
144
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:latest ./serve.sh
145
+ ```
146
+
147
+
148
+ ## Notable changes
149
+
150
+ ### Version 0.0.6
151
+
152
+ - Fixed toggle button appearing delayed on slow loading pages (see #6)
153
+ - Fixed behavior when using Material's `navigation.instant` feature (see #5)
154
+ - Added `inline` option that prevents page flickering on reload (see #4). It is now enabled by default and async is disabled by default, to prevent the flickering. To revert to the old behavior you can set `async: True` and `inline: False` in the plugin's config in your `mkdocs.yml`
155
+ - Added `theme` option that allows you to override theme detection (see #3)
156
+ - Added support for `ansible` theme (see #3)
157
+ - Added fallback to check `theme.extra.base_theme` from `mkdocs.yml` when other theme detection logic fails (see #3)
158
+ - Added `debug` option
159
+
160
+ ### Version 0.0.5
161
+
162
+ - Bug fix: On small screens with the material theme the navigation would be hidden, even when the hamburger menu was opened.
163
+
164
+ ### Version 0.0.4
165
+
166
+ - Export API via `MkdocsToggleSidebarPlugin` object.
167
+ This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
168
+ - Added `toggle_button` option and implemented it for Material theme.
169
+
170
+ ### Version 0.0.3
171
+
172
+ - Changed internal API:
173
+ - Element hiding/restyling is now done via CSS, so it is easier to undo. You should no longer have problems on devices with small screens (like phones) having broken layouts.
174
+
175
+ ### Version 0.0.2
176
+
177
+ - Added support for `mkdocs` and `readthedocs` theme.
178
+
179
+ ### Version 0.0.1
180
+
181
+ - Prototype with `mkdocs-material` implementation.
@@ -1,9 +1,9 @@
1
1
  [metadata]
2
2
  name = mkdocs-toggle-sidebar-plugin
3
- version = 0.0.4
3
+ version = 0.0.6
4
4
  author = six-two
5
5
  author_email = pip@six-two.dev
6
- description = Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
6
+ description = Add keybindings to toggle the navigation and table of contents sidebars
7
7
  long_description = file: README.md
8
8
  long_description_content_type = text/markdown
9
9
  url = https://github.com/six-two/mkdocs-toggle-sidebar-plugin
@@ -15,6 +15,8 @@ classifiers =
15
15
  Programming Language :: Python :: 3.9
16
16
  Programming Language :: Python :: 3.10
17
17
  Programming Language :: Python :: 3.11
18
+ Programming Language :: Python :: 3.12
19
+ Programming Language :: Python :: 3.13
18
20
 
19
21
  [options]
20
22
  include_package_data = True
@@ -24,7 +26,7 @@ packages = find:
24
26
  python_requires = >=3.9
25
27
  scripts =
26
28
  install_requires =
27
- mkdocs>=1.4.0
29
+ mkdocs>=1.5.0
28
30
 
29
31
  [options.entry_points]
30
32
  mkdocs.plugins =
@@ -0,0 +1,135 @@
1
+ import os
2
+ # pip dependency
3
+ from mkdocs.plugins import BasePlugin, get_plugin_logger
4
+ from mkdocs.config.defaults import MkDocsConfig
5
+ from mkdocs.config.base import Config
6
+ from mkdocs.config.config_options import Type, ExtraScriptValue
7
+ from mkdocs.exceptions import PluginError
8
+
9
+ LOGGER = get_plugin_logger(__name__)
10
+ SCRIPT_DIR = os.path.dirname(__file__)
11
+ ALLOWED_TOGGLE_BUTTON_VALUES = ["none", "navigation", "toc", "all"]
12
+ # This is a map of compatible themes. For example 'ansible' inherits from 'material', so the material javascript will work for the ansible theme too
13
+ THEME_COMPATIBILITY = {
14
+ "ansible": "material",
15
+ }
16
+ # May not always be accurate, this is just for a more helpful error message
17
+ KNOWN_THEME_NAMES = ["material", "mkdocs", "readthedocs"] + list(THEME_COMPATIBILITY.keys())
18
+
19
+ class PluginConfig(Config):
20
+ enabled = Type(bool, default=True)
21
+ show_toc_by_default = Type(bool, default=True)
22
+ show_navigation_by_default = Type(bool, default=True)
23
+ theme = Type(str, default="auto")
24
+ toggle_button = Type(str, default="none")
25
+ async_ = Type(bool, default=False)
26
+ javascript = Type(str, default="assets/javascripts/toggle-sidebar.js")
27
+ debug = Type(bool, default=False)
28
+ inline = Type(bool, default=True)
29
+
30
+
31
+ def is_known_theme(theme_name: str) -> bool:
32
+ # If the theme is known to be based on another theme, then we resolve it to the base theme
33
+ theme_name = THEME_COMPATIBILITY.get(theme_name, theme_name)
34
+
35
+ # Then we check if we have a javascript file for the theme
36
+ theme_path = os.path.join(SCRIPT_DIR, f"{theme_name}.js")
37
+ return os.path.exists(theme_path) and theme_name != "toggle-sidebar"
38
+
39
+ def get_unknown_theme_message(theme_name: str, auto_detect_enabled: bool) -> str:
40
+ if auto_detect_enabled:
41
+ basic_help = "If this theme is based on or similar to one of the supported themes above, add 'theme: <NAME_OF_SIMILAR_SUPPORTED_THEME>' to this plugin's configuration in your mkdocs.yml"
42
+ else:
43
+ basic_help = "You are overwriting the theme in this plugin's configuration in your mkdocs.yml. Make sure you spelled the theme's name correctly."
44
+ return f"Theme '{theme_name}' is not (yet) supported. The currently supported themes are: {', '.join(KNOWN_THEME_NAMES)}.\nRecommended steps:\n1. {basic_help}\n2. Try updating this plugin to the latest version: pip install -U mkdocs-toggle-sidebar-plugin\n3. Check if an issue for this theme exists: https://github.com/six-two/mkdocs-toggle-sidebar-plugin/issues\n4. If no issue exists feel free to open one. Please put the theme name and path where to download it in the issue"
45
+
46
+
47
+ class Plugin(BasePlugin[PluginConfig]):
48
+ def on_config(self, config: MkDocsConfig, **kwargs) -> MkDocsConfig:
49
+ """
50
+ Called once when the config is loaded.
51
+ It will make modify the config and initialize this plugin.
52
+ """
53
+ self.theme_function_definitions = None
54
+ self.inline_javascript = None
55
+ if self.config.enabled:
56
+ theme_name = self.config.theme
57
+ # Default to automatically determining the theme
58
+ if theme_name == "auto" or not theme_name:
59
+ theme_name = config.theme.name or "mkdocs"
60
+ base_theme_name = config.theme.get("extra", {}).get("base_theme") # check mkdocs.yml:theme.extra.base_theme
61
+ self.debug(f"Automatically detected theme: {theme_name}. Optional base theme: {base_theme_name}")
62
+
63
+ if not is_known_theme(theme_name):
64
+ # Handle themes
65
+ if base_theme_name and is_known_theme(base_theme_name):
66
+ LOGGER.debug(f"Theme is unknown, so we fell back to base theme: {base_theme_name}")
67
+ theme_name = base_theme_name
68
+ else:
69
+ LOGGER.warning(get_unknown_theme_message(theme_name, True))
70
+ else:
71
+ if not is_known_theme(theme_name):
72
+ LOGGER.warning(get_unknown_theme_message(theme_name, False))
73
+
74
+ # If the theme is known to be based on another theme, then we resolve it to the base theme
75
+ resolved_theme_name = THEME_COMPATIBILITY.get(theme_name, theme_name)
76
+
77
+ theme_path = os.path.join(SCRIPT_DIR, f"{resolved_theme_name}.js")
78
+ if os.path.exists(theme_path):
79
+ self.debug(f"Using JavaScript {resolved_theme_name}.js for theme {theme_name}")
80
+ with open(theme_path) as f:
81
+ self.theme_function_definitions = f.read()
82
+
83
+ if self.theme_function_definitions:
84
+ if self.config.inline:
85
+ # We cache it for performance reasons
86
+ self.inline_javascript = f"<script>{self.get_toggle_sidebar_javascript()}</script>"
87
+ else:
88
+ # Add a custom script reference
89
+ custom_script = ExtraScriptValue(self.config.javascript)
90
+ if self.config.async_:
91
+ custom_script.async_ = True
92
+
93
+ config.extra_javascript.append(custom_script)
94
+
95
+ if self.config.toggle_button not in ALLOWED_TOGGLE_BUTTON_VALUES:
96
+ raise PluginError(f"Unexpected value for 'toggle_button': '{self.config.toggle_button}'. Allowed values are {', '.join(ALLOWED_TOGGLE_BUTTON_VALUES)}")
97
+ return config
98
+
99
+ def debug(self, message: str) -> None:
100
+ if self.config.debug:
101
+ LOGGER.info(message)
102
+ else:
103
+ LOGGER.debug(message)
104
+
105
+ def on_post_page(self, html, /, *, page, config):
106
+ if self.inline_javascript:
107
+ html = html.replace("</head>", self.inline_javascript + "</head>")
108
+ return html
109
+
110
+ def on_post_build(self, config: MkDocsConfig) -> None:
111
+ if self.theme_function_definitions and not self.config.inline:
112
+ target_path = os.path.join(config.site_dir, self.config.javascript)
113
+ if os.path.exists(target_path):
114
+ # The file exists. This probably means, that the user wanted to override the default file
115
+ # So we just do nothing
116
+ pass
117
+ else:
118
+ # Make sure that the folder exists
119
+ parent_dir = os.path.dirname(target_path)
120
+ os.makedirs(parent_dir, exist_ok=True)
121
+
122
+ # Copy the file, while also editing it on the fly
123
+ javascript = self.get_toggle_sidebar_javascript()
124
+ with open(target_path, "w") as f:
125
+ f.write(javascript)
126
+
127
+ def get_toggle_sidebar_javascript(self):
128
+ asset_path = os.path.join(SCRIPT_DIR, "toggle-sidebar.js")
129
+ with open(asset_path) as f:
130
+ data = f.read()
131
+ data = data.replace("THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER", self.theme_function_definitions)
132
+ data = data.replace("TOC_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
133
+ data = data.replace("NAVIGATION_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
134
+ data = data.replace("TOGGLE_BUTTON_PLACEHOLDER", self.config.toggle_button)
135
+ return data
@@ -1,4 +1,7 @@
1
1
  const setCombinedVisibility = (showNavigation, showTOC) => {
2
+ // Hide the button when on mobile (and menu us shown as hamburger menu anyways).
3
+ // The exact max-width is taken from the styling of the 'body > header > nav > a' element
4
+
2
5
  let style = `
3
6
  .mkdocs-toggle-sidebar-button {
4
7
  cursor: pointer;
@@ -6,31 +9,34 @@ const setCombinedVisibility = (showNavigation, showTOC) => {
6
9
  margin-left: 1rem;
7
10
  }
8
11
 
9
- /*
10
- Hide the button when on mobile (and menu us shown as hamburger menu anyways).
11
- The exact max-width is taken from the styling of the 'body > header > nav > a' element
12
- */
13
-
14
12
  @media screen and (max-width: 76.1875em) {
15
13
  .mkdocs-toggle-sidebar-button {
16
14
  display: none;
17
15
  }
18
16
  }
19
17
  `;
20
- if (!showTOC) {
21
- style += `
22
- div.md-sidebar.md-sidebar--secondary {
23
- display: none;
18
+ // The TOC has a different break point than the navigation.
19
+ // It can be seen on the nav.md-nav--secondary:nth-child(1) element (60em)
20
+ // If the screen is smaller, it is shown in the navigation section if you click the nested hamburger menu
21
+ if (!showTOC) {
22
+ style += `
23
+ @media screen and (min-width: 60em) {
24
+ div.md-sidebar.md-sidebar--secondary {
25
+ display: none;
26
+ }
24
27
  }
25
28
  `;
26
- }
27
-
29
+ }
30
+
31
+ // We always have to show the navigation in mobile view, otherwise the hamburger menu is broken
28
32
  if (!showNavigation) {
29
33
  style += `
30
- div.md-sidebar.md-sidebar--primary {
31
- display: none;
34
+ @media screen and (min-width: 76.1875em) {
35
+ div.md-sidebar.md-sidebar--primary {
36
+ display: none;
37
+ }
32
38
  }
33
- `
39
+ `;
34
40
  }
35
41
 
36
42
  return style;
@@ -1,6 +1,7 @@
1
1
  (function() {
2
2
  const customDynamicStyle = document.createElement("style");
3
- document.head.appendChild(customDynamicStyle);
3
+ // We must put it outside of the head and body, since they are replaced by the instant navigation feature in the Material theme
4
+ document.documentElement.appendChild(customDynamicStyle);
4
5
 
5
6
  const TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING = "[mkdocs-toggle-sidebar-plugin] Reference element for inserting 'toggle_button' not found. This version of the plugin may not be compatible with this version of the theme. Try updating both to the latest version. If that fails, you can open an GitHub issue.";
6
7
 
@@ -65,7 +66,7 @@
65
66
  }
66
67
  }
67
68
 
68
- window.addEventListener("load", () => {
69
+ const onPageLoadedAction = () => {
69
70
  console.log("The mkdocs-toggle-sidebar-plugin is installed. It adds the following key bindings:\n T -> toggle table of contents sidebar\n M -> toggle navigation menu sidebar\n B -> toggle both sidebars (TOC and navigation)");
70
71
 
71
72
  const toggle_button = "TOGGLE_BUTTON_PLACEHOLDER";
@@ -82,8 +83,7 @@
82
83
  }
83
84
 
84
85
  registerKeyboardEventHandler();
85
- customDynamicStyle.innerHTML = setCombinedVisibility(loadNavigationState(), loadTocState());
86
- });
86
+ }
87
87
 
88
88
  const createDefaultToggleButton = (toggleNavigation, toggleTOC) => {
89
89
  const toggleBtn = document.createElement("div");
@@ -119,4 +119,17 @@
119
119
  toggleTocVisibility: () => toggleVisibility(false, true),
120
120
  toggleAllVisibility: () => toggleVisibility(true, true)
121
121
  };
122
+
123
+ // Run this immediately instead of waiting for page.onload to prevent page flicker
124
+ customDynamicStyle.innerHTML = setCombinedVisibility(loadNavigationState(), loadTocState());
125
+ // console.log("Debug: hide sidebar completed");
126
+
127
+ // SEE https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#checking_whether_loading_is_already_complete
128
+ if (document.readyState === "loading") {
129
+ // console.debug("Registering DOMContentLoaded event listener");
130
+ document.addEventListener("DOMContentLoaded", onPageLoadedAction);
131
+ } else {
132
+ // console.debug("DOMContentLoaded has already fired");
133
+ onPageLoadedAction();
134
+ }
122
135
  }());
@@ -1,7 +1,7 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: mkdocs-toggle-sidebar-plugin
3
- Version: 0.0.4
4
- Summary: Add keybindings to toggle the table of contents and menu sidebars on some MkDocs themes
3
+ Version: 0.0.6
4
+ Summary: Add keybindings to toggle the navigation and table of contents sidebars
5
5
  Home-page: https://github.com/six-two/mkdocs-toggle-sidebar-plugin
6
6
  Author: six-two
7
7
  Author-email: pip@six-two.dev
@@ -12,10 +12,13 @@ Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.9
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
15
17
  Requires-Python: >=3.9
16
18
  Description-Content-Type: text/markdown
17
19
  License-File: LICENSE
18
- Requires-Dist: mkdocs>=1.4.0
20
+ Requires-Dist: mkdocs>=1.5.0
21
+ Dynamic: license-file
19
22
 
20
23
  # mkdocs-toggle-sidebar-plugin
21
24
 
@@ -64,7 +67,41 @@ Key | Action
64
67
  For some themes like `readthedocs` navigation and TOC are combined.
65
68
  In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
66
69
 
67
- ### Toggle button
70
+ ### Configuration options
71
+
72
+ You can overwrite the defaults like this:
73
+
74
+ ```yaml
75
+ plugins:
76
+ - search
77
+ - toggle-sidebar:
78
+ async: False
79
+ debug: True
80
+ enabled: True
81
+ inline: False
82
+ javascript: ./toggle-sidebar.js
83
+ show_navigation_by_default: False
84
+ show_toc_by_default: False
85
+ theme: material
86
+ toggle_button: all
87
+ ```
88
+
89
+ The following options exist:
90
+
91
+ Option | Type | Default value | Description
92
+ --- | ---| --- | ---
93
+ async | `bool` | `False` | Asynchronously load the JavaScript file created by the plugin
94
+ debug | `bool` | `False` | Show some debug messages during mkdocs build (for example related to theme detection)
95
+ enabled | `bool` | `True` | Can be used to disable the plugin. Usually used in combination with environment variables like `enabled: !ENV [TOGGLE_SIDEBAR, false]` as described in [mkdocs's docs](https://www.mkdocs.org/user-guide/configuration/#enabled-option)
96
+ inline | `bool` | `True` | Instead of storing the javascript code in the file specified by `javascript`, it is directly copied into each page. Slightly increases page size, but can improve load times a little bit and reduce flickering on page (re-)load
97
+ javascript | `str` | `"assets/javascripts/toggle-sidebar.js"` | The path where to store the output file
98
+ show_navigation_by_default | `bool` | `True` | Whether to show the navigation by default
99
+ show_toc_by_default | `bool` | `True` | Whether to show the table of contents by default
100
+ theme | `str` | `auto` | Used for theme detection. With `auto`, the plugin tries to automatically detect the theme. But you can also force it to use a specific theme preset that you know will work. Currently supported values: `material`/`ansible`, `mkdocs`, `readthedocs`.
101
+ toggle_button | `str` | `"none"` | Can be set to show a toggle button (see below)
102
+
103
+
104
+ #### Toggle button
68
105
 
69
106
  When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
70
107
  It is usually in the nav or the top bar.
@@ -90,35 +127,67 @@ The names and parameters should be self-explanatory.
90
127
  ## Theme support
91
128
 
92
129
  Below shows the latest themes that I have tested.
93
- They are not updated that often, and the plugin should generally work for other of theme versions too.
130
+ The table is not updated regularly, but the plugin should generally work for other theme versions too.
94
131
 
95
132
  Theme | Theme version | Plugin version | Status
96
133
  --- | --- | --- | ---
97
- mkdocs-material | 9.5.34 | 0.0.4 | works
98
- mkdocs (default) | 1.6.1 | 0.0.4 | works
99
- readthedocs | 1.6.1 | 0.0.4 | works
134
+ mkdocs-ansible | 25.6.0 | 0.0.6 | works
135
+ mkdocs-material | 9.6.14 | 0.0.4+ | works
136
+ mkdocs (default) | 1.6.1 | 0.0.4+ | works
137
+ readthedocs | 1.6.1 | 0.0.4+ | works
100
138
 
101
- Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
139
+ Just open an issue / PR if you use a strange theme or the info above is not up-to-date anymore.
102
140
 
103
141
  ### Note to self
104
142
 
105
- Test mkdocs-material theme:
143
+ Test `material` theme:
106
144
  ```bash
107
145
  ./serve.sh
108
146
  ```
109
147
 
110
- Test mkdocs theme:
148
+ Test `mkdocs` theme:
111
149
  ```bash
112
150
  ./serve.sh --theme mkdocs
113
151
  ```
114
152
 
153
+ Test `mkdocs`, `readthedocs` and `material` themes:
154
+ ```bash
155
+ ./build.sh
156
+ python3 -m http.server --directory './public/'
157
+ ```
158
+
159
+ Test oldest python version supported by me (3.9):
160
+ ```bash
161
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:3.9 ./serve.sh
162
+ ```
163
+
164
+ Test newest available python version (currently 3.13):
165
+ ```bash
166
+ docker run --rm -it -v "$PWD:/share" -w "/share" -p 8000:8000 --entrypoint=bash python:latest ./serve.sh
167
+ ```
168
+
169
+
115
170
  ## Notable changes
116
171
 
172
+ ### Version 0.0.6
173
+
174
+ - Fixed toggle button appearing delayed on slow loading pages (see #6)
175
+ - Fixed behavior when using Material's `navigation.instant` feature (see #5)
176
+ - Added `inline` option that prevents page flickering on reload (see #4). It is now enabled by default and async is disabled by default, to prevent the flickering. To revert to the old behavior you can set `async: True` and `inline: False` in the plugin's config in your `mkdocs.yml`
177
+ - Added `theme` option that allows you to override theme detection (see #3)
178
+ - Added support for `ansible` theme (see #3)
179
+ - Added fallback to check `theme.extra.base_theme` from `mkdocs.yml` when other theme detection logic fails (see #3)
180
+ - Added `debug` option
181
+
182
+ ### Version 0.0.5
183
+
184
+ - Bug fix: On small screens with the material theme the navigation would be hidden, even when the hamburger menu was opened.
185
+
117
186
  ### Version 0.0.4
118
187
 
119
188
  - Export API via `MkdocsToggleSidebarPlugin` object.
120
189
  This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
121
- - Added `toggle_button` option and implemented it for Material theme
190
+ - Added `toggle_button` option and implemented it for Material theme.
122
191
 
123
192
  ### Version 0.0.3
124
193
 
@@ -1,115 +0,0 @@
1
- # mkdocs-toggle-sidebar-plugin
2
-
3
- [![PyPI version](https://img.shields.io/pypi/v/mkdocs-toggle-sidebar-plugin)](https://pypi.org/project/mkdocs-toggle-sidebar-plugin/)
4
- ![License](https://img.shields.io/pypi/l/mkdocs-toggle-sidebar-plugin)
5
- ![Python versions](https://img.shields.io/pypi/pyversions/mkdocs-toggle-sidebar-plugin)
6
-
7
- This package allows you to toggle the left (navigation) and right (table of contents) sidebars on a couple of MkDocs themes such as:
8
-
9
- - [Material for MkDocs](https://github.com/squidfunk/mkdocs-material): `material`
10
- - Builtin themes: `mkdocs`, `readthedocs`
11
-
12
- You can play around with it and these themes on the [test page](https://mkdocs-toggle-sidebar.six-two.dev).
13
-
14
- The settings are stored using the `localStorage` object, so that it will persist between pages.
15
-
16
- I wrote it after getting frustrated by the browser's `Find in page` function matching way to many links in the navigation sidebar instead of searching in the actual page's content.
17
-
18
-
19
- ## Usage
20
-
21
- ### Setup
22
-
23
- First install the PyPI package:
24
- ```bash
25
- pip install mkdocs-toggle-sidebar-plugin
26
- ```
27
-
28
- Add something like the following to your `mkdocs.yml`:
29
- ```yaml
30
- plugins:
31
- - search
32
- - toggle-sidebar
33
- ```
34
-
35
- ### Key bindings
36
-
37
- The plugin adds the following key bindings:
38
-
39
- Key | Action
40
- --- | ---
41
- `b` | toggle **b**oth (TOC and navigation)
42
- `m` | toggle navigation **m**enu
43
- `t` | toggle **T**OC
44
-
45
- For some themes like `readthedocs` navigation and TOC are combined.
46
- In this case the state of TOC is ignored, and only calls for navigation (or all) are interpreted.
47
-
48
- ### Toggle button
49
-
50
- When you set the `toggle_button` option to `navigation`, `toc` or `all`, it will add a button that looks like a hamburger menu (three horizontal bars) on a theme-dependent location.
51
- It is usually in the nav or the top bar.
52
- Clicking the button will toggle the navigation, table of contents, or both (depending on the supplied value).
53
- By leaving the field empty or setting it to `none`, no button is added.
54
-
55
- ### Exported API functions
56
-
57
- This plugin exposes some JavaScript functions, that can show, hide or toggle the visibility of the sidebars.
58
- You can see how they are called in `docs/javascript-functions.md` and how they are defined in `src/mkdocs_toggle_sidebar_plugin/toggle-sidebar.js`.
59
-
60
- In short there are:
61
-
62
- - `MkdocsToggleSidebarPlugin.setNavigationVisibility(show: bool)`
63
- - `MkdocsToggleSidebarPlugin.setTocVisibility(show: bool)`
64
- - `MkdocsToggleSidebarPlugin.setAllVisibility: (showNavigation: bool, showTOC: bool)`
65
- - `MkdocsToggleSidebarPlugin.toggleNavigationVisibility()`
66
- - `MkdocsToggleSidebarPlugin.toggleTocVisibility()`
67
- - `MkdocsToggleSidebarPlugin.toggleAllVisibility()`
68
-
69
- The names and parameters should be self-explanatory.
70
-
71
- ## Theme support
72
-
73
- Below shows the latest themes that I have tested.
74
- They are not updated that often, and the plugin should generally work for other of theme versions too.
75
-
76
- Theme | Theme version | Plugin version | Status
77
- --- | --- | --- | ---
78
- mkdocs-material | 9.5.34 | 0.0.4 | works
79
- mkdocs (default) | 1.6.1 | 0.0.4 | works
80
- readthedocs | 1.6.1 | 0.0.4 | works
81
-
82
- Just open a issue / PR if you use a strange theme or the info above is not up to date anymore.
83
-
84
- ### Note to self
85
-
86
- Test mkdocs-material theme:
87
- ```bash
88
- ./serve.sh
89
- ```
90
-
91
- Test mkdocs theme:
92
- ```bash
93
- ./serve.sh --theme mkdocs
94
- ```
95
-
96
- ## Notable changes
97
-
98
- ### Version 0.0.4
99
-
100
- - Export API via `MkdocsToggleSidebarPlugin` object.
101
- This lets you create custom buttons or key bindings to hide, show or toggle the side bars.
102
- - Added `toggle_button` option and implemented it for Material theme
103
-
104
- ### Version 0.0.3
105
-
106
- - Changed internal API:
107
- - Element hiding/restyling is now done via CSS, so it is easier to undo. You should no longer have problems on devices with small screens (like phones) having broken layouts.
108
-
109
- ### Version 0.0.2
110
-
111
- - Added support for `mkdocs` and `readthedocs` theme.
112
-
113
- ### Version 0.0.1
114
-
115
- - Prototype with `mkdocs-material` implementation.
@@ -1,73 +0,0 @@
1
- import os
2
- import logging
3
- # pip dependency
4
- from mkdocs.plugins import BasePlugin, get_plugin_logger
5
- from mkdocs.config.defaults import MkDocsConfig
6
- from mkdocs.config.base import Config
7
- from mkdocs.config.config_options import Type, ExtraScriptValue
8
- from mkdocs.exceptions import PluginError
9
-
10
- LOGGER = get_plugin_logger(__name__)
11
- SCRIPT_DIR = os.path.dirname(__file__)
12
- ALLOWED_TOGGLE_BUTTON_VALUES = ["none", "navigation", "toc", "all"]
13
-
14
- class PluginConfig(Config):
15
- enabled = Type(bool, default=True)
16
- show_toc_by_default = Type(bool, default=True)
17
- show_navigation_by_default = Type(bool, default=True)
18
- toggle_button = Type(str, default="none")
19
- async_ = Type(bool, default=True)
20
- javascript = Type(str, default="assets/javascripts/toggle-sidebar.js")
21
-
22
-
23
- class Plugin(BasePlugin[PluginConfig]):
24
- def on_config(self, config: MkDocsConfig, **kwargs) -> MkDocsConfig:
25
- """
26
- Called once when the config is loaded.
27
- It will make modify the config and initialize this plugin.
28
- """
29
- self.theme_function_definitions = None
30
- if self.config.enabled:
31
- theme_name = config.theme.name or "mkdocs"
32
- theme_path = os.path.join(SCRIPT_DIR, f"{theme_name}.js")
33
- if os.path.exists(theme_path):
34
- with open(theme_path) as f:
35
- self.theme_function_definitions = f.read()
36
- else:
37
- LOGGER.warning(f"[toggle-sidebar] Theme '{theme_name}' is not (yet) supported. Hint:\n1. Try updating the plugin to the latest version: pip install -U mkdocs-toggle-sidebar-plugin\n2. Check if an issue for this theme exists: https://github.com/six-two/mkdocs-toggle-sidebar-plugin/issues\n3. If no issue exists feel free to open one. Please put the theme name and path where to download it in the issue")
38
-
39
- if self.theme_function_definitions:
40
- custom_script = ExtraScriptValue(self.config.javascript)
41
- if self.config.async_:
42
- custom_script.async_ = True
43
-
44
- config.extra_javascript.append(custom_script)
45
-
46
- if self.config.toggle_button not in ALLOWED_TOGGLE_BUTTON_VALUES:
47
- raise PluginError(f"Unexpected value for 'toggle_button': '{self.config.toggle_button}'. Allowed values are {', '.join(ALLOWED_TOGGLE_BUTTON_VALUES)}")
48
- return config
49
-
50
-
51
- def on_post_build(self, config: MkDocsConfig) -> None:
52
- if self.theme_function_definitions:
53
- target_path = os.path.join(config.site_dir, self.config.javascript)
54
- if os.path.exists(target_path):
55
- # The file exists. This probably means, that the user wanted to override the default file
56
- # So we just do nothing
57
- pass
58
- else:
59
- # Make sure that the folder exists
60
- parent_dir = os.path.dirname(target_path)
61
- os.makedirs(parent_dir, exist_ok=True)
62
-
63
- # Copy the file, while also editing it on the fly
64
- asset_path = os.path.join(SCRIPT_DIR, "toggle-sidebar.js")
65
- with open(asset_path) as f:
66
- data = f.read()
67
- data = data.replace("THEME_DEPENDENT_FUNCTION_DEFINITION_PLACEHOLDER", self.theme_function_definitions)
68
- data = data.replace("TOC_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
69
- data = data.replace("NAVIGATION_DEFAULT_PLACEHOLDER", "true" if self.config.show_toc_by_default else "false")
70
- data = data.replace("TOGGLE_BUTTON_PLACEHOLDER", self.config.toggle_button)
71
- with open(target_path, "w") as f:
72
- f.write(data)
73
-