mkdocs-docdive 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,65 @@
1
+ """docdive adapter for MkDocs. Data only: the product logic lives in the `docdive` CLI."""
2
+
3
+ import json
4
+ import re
5
+ import shlex
6
+ import shutil
7
+ import subprocess
8
+ from pathlib import Path
9
+ from urllib.parse import urlparse
10
+
11
+ from mkdocs.config import base
12
+ from mkdocs.config import config_options as c
13
+ from mkdocs.config.defaults import MkDocsConfig
14
+ from mkdocs.exceptions import PluginError
15
+ from mkdocs.plugins import BasePlugin
16
+ from mkdocs.structure.files import Files
17
+ from mkdocs.structure.pages import Page
18
+
19
+ from . import __version__
20
+
21
+ FENCE = re.compile(r'(<pre class="mermaid">.*?</pre>)', re.DOTALL)
22
+ ELEMENT_SCRIPT = "docdive/docdive-element.js"
23
+
24
+
25
+ class DocdiveConfig(base.Config):
26
+ # How to run the docdive CLI. Pin it to this plugin's version so the two cannot drift apart.
27
+ command = c.Type(str, default=f"npx --yes docdive@{__version__}")
28
+ # Repo root that `src:` frontmatter paths are relative to (optional).
29
+ src = c.Optional(c.Type(str))
30
+
31
+
32
+ class DocdivePlugin(BasePlugin[DocdiveConfig]):
33
+ def __init__(self) -> None:
34
+ self.doc_urls: dict[str, str] = {}
35
+
36
+ def on_config(self, config: MkDocsConfig) -> MkDocsConfig:
37
+ script = c.ExtraScriptValue(ELEMENT_SCRIPT)
38
+ script.type = "module"
39
+ config.extra_javascript.append(script)
40
+ return config
41
+
42
+ def on_files(self, files: Files, config: MkDocsConfig) -> Files:
43
+ # src_uri -> site-absolute URL (site_url path + file url), so the element needs no base-URL logic.
44
+ base_path = urlparse(config.site_url or "").path.rstrip("/")
45
+ self.doc_urls = {f.src_uri: f"{base_path}/{f.url}" for f in files.documentation_pages()}
46
+ return files
47
+
48
+ def on_page_content(self, html: str, page: Page, config: MkDocsConfig, files: Files) -> str:
49
+ # Wrap the fence before the theme mounts it; the element takes the text out of the light DOM.
50
+ return FENCE.sub(r"<docdive-diagram>\1</docdive-diagram>", html)
51
+
52
+ def on_post_build(self, config: MkDocsConfig) -> None:
53
+ dest = Path(config.site_dir) / "docdive"
54
+ command = shlex.split(self.config.command)
55
+ executable = shutil.which(command[0])
56
+ if executable is None:
57
+ raise PluginError(f"docdive: cannot run `{command[0]}`; Node.js >= 22.12 is required at build time")
58
+ args = [executable, *command[1:], "build", str(config.docs_dir), "--out", str(dest)]
59
+ if self.config.src:
60
+ args += ["--src", str(Path(self.config.src).resolve())]
61
+ try:
62
+ subprocess.run(args, check=True)
63
+ except subprocess.CalledProcessError as error:
64
+ raise PluginError(f"docdive: `{' '.join(args)}` exited with {error.returncode}") from error
65
+ (dest / "docdive-map.json").write_text(json.dumps(self.doc_urls, indent=2) + "\n")
@@ -0,0 +1,45 @@
1
+ Metadata-Version: 2.5
2
+ Name: mkdocs-docdive
3
+ Version: 0.1.0
4
+ Summary: MkDocs plugin that renders Mermaid fences as interactive docdive diagrams.
5
+ Project-URL: Repository, https://github.com/thibaudnavarre/docdive
6
+ Author: Thibaud Navarre
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: mermaid,mkdocs,mkdocs-plugin
10
+ Classifier: Framework :: MkDocs
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.11
14
+ Requires-Dist: mkdocs<2,>=1.6
15
+ Description-Content-Type: text/markdown
16
+
17
+ # mkdocs-docdive
18
+
19
+ [docdive](https://github.com/thibaudnavarre/docdive) plugin for MkDocs: renders Mermaid fences as interactive
20
+ `<docdive-diagram>` elements and, after the build, writes the index and assets to `<site>/docdive/`.
21
+
22
+ ```bash
23
+ pip install mkdocs-docdive
24
+ ```
25
+
26
+ ```yaml
27
+ # mkdocs.yml
28
+ site_url: https://example.com/docs/ # required
29
+ markdown_extensions:
30
+ - pymdownx.superfences:
31
+ custom_fences:
32
+ - name: mermaid
33
+ class: mermaid
34
+ format: !!python/name:pymdownx.superfences.fence_code_format
35
+ plugins:
36
+ - docdive
37
+ ```
38
+
39
+ Options:
40
+
41
+ - `command`: how to run the docdive CLI. Default `npx --yes docdive@<this plugin's version>`; Node >= 22.12 is needed at
42
+ build time.
43
+ - `src`: repo root that `src:` frontmatter paths are relative to (optional).
44
+
45
+ Supports `mkdocs>=1.6,<2` and Python >= 3.11. MkDocs 2.0 has no plugin system and is not supported. MIT.
@@ -0,0 +1,7 @@
1
+ mkdocs_docdive/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
2
+ mkdocs_docdive/plugin.py,sha256=nkuBbwhaAJI-uQEe_WJrkSbfoDR2VngpVrg_q7UO6SI,2782
3
+ mkdocs_docdive-0.1.0.dist-info/METADATA,sha256=lIJJFzr0PL_tZ96oRmmQLDtcAW5-uDjYglJKi6Ft_-4,1426
4
+ mkdocs_docdive-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
5
+ mkdocs_docdive-0.1.0.dist-info/entry_points.txt,sha256=k4Iks8-FzZhJYG2mzJxM4V_MWLtquZ-mNhhxNjrkHCI,63
6
+ mkdocs_docdive-0.1.0.dist-info/licenses/LICENSE,sha256=wv8AKLAjpFSORY7xkxuFQb-otjbY1MwRdsFpBYTQFgc,1072
7
+ mkdocs_docdive-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [mkdocs.plugins]
2
+ docdive = mkdocs_docdive.plugin:DocdivePlugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thibaud Navarre
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.