-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add dynamic theme colors and attr_list support for paging #21
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
Changes from all commits
5efade9
a1ef253
30db9a6
58aec35
83c082f
4381706
a92d841
e7d7ed2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,14 +10,38 @@ jobs: | |
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: "3.x" | ||
|
|
||
| - name: Install pypa/build | ||
| run: python3 -m pip install build poetry --user | ||
| - name: Install Poetry | ||
| uses: snok/install-poetry@v1 | ||
| - name: Check | ||
| run: | | ||
| poetry run ruff check . | ||
| poetry run black --check . | ||
|
|
||
| - name: Install | ||
| run: poetry install | ||
|
|
||
| - name: Test the build | ||
| run: python3 -m build | ||
| - name: Build | ||
| run: poetry build | ||
| documentation: | ||
| runs-on: ubuntu-latest | ||
| if: startsWith(github.ref, 'refs/tags') | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| - name: Install Poetry | ||
| uses: snok/install-poetry@v1 | ||
| - name: Build site | ||
| run: | | ||
| poetry install | ||
| poetry run mkdocs build -f documentation/mkdocs-material.yml | ||
| - name: Build and Deploy | ||
| uses: JamesIves/[email protected] | ||
| with: | ||
| ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
| BRANCH: gh-pages | ||
| FOLDER: documentation/site | ||
|
Comment on lines
+42
to
+47
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same goes for this one. Lets use the official GitHub Action for deploying pages: |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| # MkDocs Plugin for embedding Drawio files | ||
|
|
||
| [](https://github.com/tuunit/mkdocs-drawio/actions) | ||
| [](https://pypi.org/project/mkdocs-drawio/) | ||
|
|
||
| [Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin) | ||
| [Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin) | ||
|
|
||
| Sergey ([onixpro](https://github.com/onixpro)) is the original creator of this plugin. Repo can be found [here.](https://github.com/onixpro/mkdocs-drawio-file) | ||
|
|
||
| ## Features | ||
|
|
||
| This plugin enables you to embed interactive drawio diagrams in your documentation. Simply add your diagrams like you would any other image: | ||
|
|
||
| ```markdown | ||
|
|
@@ -26,18 +28,27 @@ Or you can use external urls: | |
|  | ||
| ``` | ||
|
|
||
| Additionally this plugin supports multi page diagrams by using the `alt` text to select the pages by name: | ||
| Additionally this plugin supports multi page diagrams by using either the `page` or `alt` property. To use the `page` property, you need to use the markdown extension `attr_list`. | ||
|
|
||
| With `alt_as_page: True` which is the default: | ||
|
|
||
| ```markdown | ||
|  | ||
|  | ||
| ``` | ||
|
|
||
| With `alt_as_page: False`: | ||
|
|
||
| ```markdown | ||
| { page="Page-2" } | ||
| { page="my-custom-page-name" } | ||
| ``` | ||
|
|
||
| ## Setup | ||
|
|
||
| Install plugin using pip: | ||
|
|
||
| ``` | ||
| ```bash | ||
| pip install mkdocs-drawio | ||
| ``` | ||
|
|
||
|
|
@@ -68,7 +79,8 @@ plugins: | |
| toolbar: true # control if hovering on a diagram shows a toolbar for zooming or not (default: true) | ||
| tooltips: true # control if tooltips will be shown (default: true) | ||
| edit: true # control if edit button will be shown in the lightbox view (default: true) | ||
| border: 10 # increase or decrease the border / margin around your diagrams (default: 5) | ||
| border: 10 # increase or decrease the border / margin around your diagrams (default: 5) | ||
| alt_as_page: true # use the alt text as page name (default: false) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small thing but can you indent all comments to the same level?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
| ``` | ||
|
|
||
| ## Material Integration | ||
|
|
@@ -107,7 +119,6 @@ document$.subscribe(({ body }) => { | |
| 4. Searches through the generated html for all `img` tags that have a source of type `.drawio` | ||
| 5. Replaces the found `img` tags with `mxgraph` html blocks (actual drawio diagram content). For more details, please have a look at the [official drawio.com documentation](https://www.drawio.com/doc/faq/embed-html). | ||
|
|
||
|
|
||
| ## Contribution guide | ||
|
|
||
| 1. Either use the devcontainer or setup a venv with mkdocs installed | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version='1.0' encoding='utf-8'?> | ||
| <mxfile version="26.0.7"> | ||
| <diagram name="Page-1" id="mV4jbraemd7C51ydpzk2"> | ||
| <mxGraphModel dx="565" dy="355" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="394" pageHeight="394" math="0" shadow="0"> | ||
| <root> | ||
| <mxCell id="0" /> | ||
| <mxCell id="1" parent="0" /> | ||
| <mxCell id="7JHgTfKEjFP575Ptm9la-1" value="" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1"> | ||
| <mxGeometry x="80" y="40" width="80" height="80" as="geometry" /> | ||
| </mxCell> | ||
| <mxCell id="7JHgTfKEjFP575Ptm9la-2" value="" style="whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f8cecc;strokeColor=#b85450;" vertex="1" parent="1"> | ||
| <mxGeometry x="180" y="40" width="80" height="80" as="geometry" /> | ||
| </mxCell> | ||
| </root> | ||
| </mxGraphModel> | ||
| </diagram> | ||
| </mxfile> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # Configuration | ||
|
|
||
| ## Diagram options | ||
|
|
||
| By default the plugin uses the official url for the minified drawio javascript library. To use a custom source for the drawio viewer you can overwritte the url. This might be useful in airlocked environments. | ||
|
|
||
| ```yaml | ||
| plugins: | ||
| - drawio: | ||
| viewer_js: "https://viewer.diagrams.net/js/viewer-static.min.js" | ||
| ``` | ||
|
|
||
| Further options are the following with their default value | ||
|
|
||
| ```yaml | ||
| plugins: | ||
| - drawio: | ||
| # Control if hovering on a diagram shows a toolbar for zooming or not | ||
| toolbar: | ||
| # Display the zoom control (data-toolbar-zoom) | ||
| zoom: true | ||
|
|
||
| # Display the page selector (data-toolbar-pages) | ||
| pages: true | ||
|
|
||
| # Display the layers control (data-toolbar-layers) | ||
| layers: true | ||
|
|
||
| # Display the lightbox button (data-toolbar-lightbox) | ||
| lightbox: true | ||
|
|
||
| # Do not hide the toolbar when hovering over the diagram | ||
| # (data-toolbar-nohide) | ||
| nohide: false | ||
|
|
||
| # Control the position of the toolbar (top or bottom) | ||
| # (data-toolbar-position) | ||
| position: "top" | ||
|
|
||
| # Control if tooltips will be shown (data-tooltips) | ||
| tooltips: true | ||
|
|
||
| # Control if edit button will be shown in the lightbox view | ||
| # (data-edit) | ||
| edit: true | ||
|
|
||
| # Increase or decrease the padding around your diagrams | ||
| # (data-border) | ||
| border: 5 | ||
|
|
||
| # Use the alt text as page name | ||
| alt_as_page: false | ||
| ``` | ||
|
|
||
| ## HTML Attributes | ||
|
|
||
| For each global configuration option you can also use the attribute in the diagram itself. This will override the global configuration. Here is an example: | ||
|
|
||
| ```markdown | ||
| { data-toolbar-zoom="false" } | ||
| ``` | ||
|
|
||
| To use these attributes you need to enable the markdown extension `attr_list` in your `mkdocs.yml`: | ||
|
|
||
| ```yaml | ||
| markdown_extensions: | ||
| - attr_list | ||
| ``` | ||
|
|
||
| ## Page selection | ||
|
|
||
| Additionally this plugin supports multi page diagrams by using either the `page` or `alt` property. To use the `page` property, you need to use the markdown extension `attr_list`. | ||
|
|
||
| By default this attribute is `True`. If you use other plugins such as `mkdocs-caption` you might want to keep `alt` for the caption. | ||
|
|
||
| === "`alt_as_page: True`" | ||
|
|
||
| ```markdown | ||
|  | ||
|  | ||
| ``` | ||
|
|
||
| === "`alt_as_page: False`" | ||
|
|
||
| ```markdown | ||
| { page="Page-2" } | ||
| { page="my-custom-page-name" } | ||
| ``` | ||
|
|
||
| In your `mkdocs.yml` you can configure the plugin to use the `alt` property instead of the `page` property: | ||
|
|
||
| ```yaml | ||
| markdown_extensions: | ||
| - attr_list | ||
| plugins: | ||
| - drawio: | ||
| alt_as_page: False | ||
| ``` |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||
| # MkDocs Drawio Plugin | ||||||
|
|
||||||
| This plugin allows you to embed draw.io diagrams in your MkDocs documentation. It is compatible with most MkDocs themes, but specifically tested with the Material theme and the MkDocs default theme. | ||||||
|
|
||||||
| Sergey ([onixpro](https://github.com/onixpro)) is the original creator of this plugin. Repo can be found [here.](https://github.com/onixpro/mkdocs-drawio-file) | ||||||
|
|
||||||
| ## Installation | ||||||
|
|
||||||
| Install the plugin using pip or poetry: | ||||||
|
|
||||||
| ```bash | ||||||
| pip install mkdocs-drawio | ||||||
| ``` | ||||||
|
|
||||||
| or | ||||||
|
|
||||||
| ```bash | ||||||
| poetry add mkdocs-drawio | ||||||
| ``` | ||||||
|
|
||||||
| Then add the plugin to your `mkdocs.yml`: | ||||||
|
|
||||||
| ```yaml | ||||||
| plugins: | ||||||
| - drawio | ||||||
| ``` | ||||||
| ## Features | ||||||
| The currently supported features are: | ||||||
| - Embed draw.io diagrams in your documentation to keep a single source of truth. | ||||||
| - Use diagrams hosted within your own docs or external urls. | ||||||
| - Support for multi page diagrams by selecting which page to display. | ||||||
| - Compatible with `mkdocs-caption` and `mkdocs-glightbox`. | ||||||
| - Match the diagram theme with your MkDocs theme (light, dark/slate). | ||||||
| - Zoom in/out. | ||||||
| - Full screen preview. | ||||||
| - Print or edit button. | ||||||
|
|
||||||
| ## Usage | ||||||
|
|
||||||
| Simply add an image as you would normally do in markdown: | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| ```markdown | ||||||
| Absolute path: | ||||||
|  | ||||||
| Same directory as the markdown file: | ||||||
|  | ||||||
| Relative directory to the markdown file: | ||||||
|  | ||||||
| Or you can use external urls: | ||||||
|  | ||||||
| ``` | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||||||||||
| # Plumbing and internals | ||||||||||||||
|
|
||||||||||||||
| For those who want to understand how the plugin works, here is a brief overview. | ||||||||||||||
|
|
||||||||||||||
| ## Diagrams.net | ||||||||||||||
|
|
||||||||||||||
| **Diagrams.net** previoully known as **Draw.io** is a free online diagram software. It is perfect for creating diagrams, flowcharts, process diagrams, and more. It is a powerful tool that can be used for creating diagrams for any purpose. | ||||||||||||||
|
Comment on lines
+5
to
+7
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never blindly trust LLMs ;)
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| It relies on JTGraph's [mxGraph](https://jgraph.github.io/mxgraph/) library to render the diagrams. A mxGraph is a XML-based language that defines the structure of the diagram. Here an example | ||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
|  | ||||||||||||||
|
|
||||||||||||||
| ```xml | ||||||||||||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||
| <mxfile host="app.diagrams.net" version="26.0.7"> | ||||||||||||||
| <diagram name="Page-1" id="mV4jbraemd7C51ydpzk2"> | ||||||||||||||
| <mxGraphModel dx="565" dy="355" grid="1" gridSize="10" | ||||||||||||||
| guides="1" tooltips="1" connect="1" arrows="1" fold="1" | ||||||||||||||
| page="1" pageScale="1" pageWidth="394" pageHeight="394" | ||||||||||||||
| math="0" shadow="0"> | ||||||||||||||
| <root> | ||||||||||||||
| <mxCell id="0" /> | ||||||||||||||
| <mxCell id="1" parent="0" /> | ||||||||||||||
| <mxCell id="7JHgTfKEjFP575Ptm9la-1" value="" | ||||||||||||||
| style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" | ||||||||||||||
| vertex="1" parent="1"> | ||||||||||||||
| <mxGeometry x="80" y="40" width="80" height="80" as="geometry" /> | ||||||||||||||
| </mxCell> | ||||||||||||||
| <mxCell id="7JHgTfKEjFP575Ptm9la-2" value="" | ||||||||||||||
| style="whiteSpace=wrap;html=1;aspect=fixed; | ||||||||||||||
| fillColor=#f8cecc;strokeColor=#b85450;" | ||||||||||||||
| vertex="1" parent="1"> | ||||||||||||||
| <mxGeometry x="180" y="40" width="80" height="80" as="geometry" /> | ||||||||||||||
| </mxCell> | ||||||||||||||
| </root> | ||||||||||||||
| </mxGraphModel> | ||||||||||||||
| </diagram> | ||||||||||||||
| </mxfile> | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ## GraphViewer | ||||||||||||||
|
|
||||||||||||||
| The plugin uses the [GraphViewer](https://github.com/jgraph/drawio/blob/dev/src/main/webapp/js/viewer-static.min.js) minified version of the drawio viewer. | ||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| This is a standalone viewer for drawio diagrams that can be embedded in any web page to convert mxGraph XML to SVG. It features a lightbox mode and a toolbar with buttons to zoom, edit, and navigate the diagram. | ||||||||||||||
|
|
||||||||||||||
| ## The Plugin | ||||||||||||||
|
|
||||||||||||||
| This plugin heavily relies on the GraphViewer to render the diagrams. The MkDocs plugin is responsible for passing configuration options to the viewer and ensure compatibility across MkDocs themes. | ||||||||||||||
|
|
||||||||||||||
| Furthermore, it provides a way to extract pages from diagrams to only serve the necessary content to the user. This is useful when you have a large diagram and only want to show a specific part of it. | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why unnecessary introduce another dependency to such a small project?
We can just do the install of poetry as before.