diff --git a/README.md b/README.md index 9f6da47..9a95fa1 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ [![Publish Badge](https://github.com/tuunit/mkdocs-drawio/workflows/Publish/badge.svg)](https://github.com/tuunit/mkdocs-drawio/actions) [![PyPI](https://img.shields.io/pypi/v/mkdocs-drawio)](https://pypi.org/project/mkdocs-drawio/) -Sergey ([onixpro](https://github.com/onixpro)) is the original creator of this plugin but since his repository isn't maintained anymore we forked it on the 19th December of 2023 and have been keeping it up-to-date and expanding on the features since then. -[Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin) +Sergey ([onixpro](https://github.com/onixpro)) is the original creator of this plugin but since his repository isn't maintained anymore we forked it on the 19th December of 2023 and have been keeping it up-to-date and expanding on the features since then. +[Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin) ## Features @@ -85,6 +85,7 @@ plugins: lightbox: true # Display the lightbox / fullscreen button position: "top" # Control the position of the toolbar (top or bottom) no_hide: false # Do not hide the toolbar when not hovering over diagrams + show_title: false # Show the diagram title in the toolbar based on the file name ``` ## Material Integration @@ -111,7 +112,14 @@ Add `docs/javascripts/drawio-reload.js` to your project: ```js document$.subscribe(({ body }) => { + // if drawio toolbar icons/buttons are not showing or missing due to title being longer than the image width + // you can set a minimum width for the graph viewer by uncommenting the following line + // GraphViewer.prototype.minWidth = 500; + GraphViewer.processElements() + + // required to fix duplicate display of external drawio graphs (via http) + reload(); }) ``` diff --git a/examples/docs/configuration.md b/examples/docs/configuration.md index 1b7cfc8..e5ec1df 100644 --- a/examples/docs/configuration.md +++ b/examples/docs/configuration.md @@ -31,8 +31,8 @@ plugins: # Enable dark mode support # When activated the color scheme for your diagrams is automatically toggled # based on the selected theme. Supports classic mkdocs and mkdocs-material. - darkmode: true - + darkmode: true + # Highlight color for hyperlinks # When a diagram element has a hyperlink on it, the element is highlighted # on mouse hover over to better indicate a hyperlink is present. @@ -63,6 +63,9 @@ plugins: # Do not hide the toolbar when not hovering over diagrams no_hide: false + + # Show the diagram title in the toolbar based on the file name + show_title: false ``` ## Material Integration @@ -89,6 +92,13 @@ Add `docs/javascripts/drawio-reload.js` to your project: ```js document$.subscribe(({ body }) => { + // if drawio toolbar icons/buttons are not showing or missing due to title being longer than the image width + // you can set a minimum width for the graph viewer by uncommenting the following line + // GraphViewer.prototype.minWidth = 500; + GraphViewer.processElements() + + // required to fix duplicate display of external drawio graphs (via http) + reload(); }) ``` diff --git a/mkdocs_drawio/plugin.py b/mkdocs_drawio/plugin.py index cb3209c..117620f 100644 --- a/mkdocs_drawio/plugin.py +++ b/mkdocs_drawio/plugin.py @@ -44,6 +44,9 @@ class Toolbar(base.Config): no_hide = c.Type(bool, default=False) """ Do not hide the toolbar when not hovering over diagrams """ + show_title = c.Type(bool, default=False) + """ Will display the original filename as toolbar title if true, no title if false """ + class DrawioConfig(base.Config): """Configuration options for the Drawio Plugin""" @@ -125,7 +128,14 @@ def get_toolbar_config(self, toolbar_config) -> Toolbar: if isinstance(toolbar_config, bool): if toolbar_config is False: # Flip all toolbar items off but keep other defaults intact. - for key in ("pages", "tags", "zoom", "layers", "lightbox"): + for key in ( + "pages", + "tags", + "zoom", + "layers", + "lightbox", + "show_title", + ): setattr(config, key, False) if isinstance(toolbar_config, dict): @@ -161,6 +171,9 @@ def render_drawio_diagrams(self, output_content, page): diagram_config = self.get_diagram_config() for diagram in diagrams: + if self.toolbar_config.show_title: + diagram_config["title"] = diagram["src"].split("/")[-1] + if re.search("^https?://", diagram["src"]): mxgraph = BeautifulSoup( DrawioPlugin.substitute_with_url(diagram_config, diagram["src"]), diff --git a/pyproject.toml b/pyproject.toml index 0dbe793..3f0712a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mkdocs-drawio" -version = "1.13.0" +version = "1.14.0" description = "MkDocs plugin for embedding Drawio files" authors = [ "Jan Larwig ",