Skip to content

Commit 93c5ec7

Browse files
docs: convert examples into actual mkdocs github page (#27)
* docs: convert examples into actual mkdocs github page Co-Authored-By: Yves Chevallier <yves.chevallier@heig-vd.ch> Signed-off-by: Jan Larwig <jan@larwig.com> * build: add docs workflow --------- Signed-off-by: Jan Larwig <jan@larwig.com> Co-authored-by: Yves Chevallier <yves.chevallier@heig-vd.ch>
1 parent 3836cb4 commit 93c5ec7

File tree

15 files changed

+351
-67
lines changed

15 files changed

+351
-67
lines changed

.github/workflows/docs.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- main
6+
permissions:
7+
contents: write
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Configure Git Credentials
14+
run: |
15+
git config user.name github-actions[bot]
16+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: 3.x
20+
- name: Install mkdocs-drawio
21+
run: |
22+
pip install poetry
23+
poetry build
24+
- name: Build and publish docs
25+
run: |
26+
cd examples
27+
pip install -r requirements.txt
28+
mkdocs gh-deploy --force

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,10 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
.idea/
161+
162+
# Backups generated from the Desktop application
163+
*.drawio.bkp
164+
165+
166+
# Temporary files generated by Windows on WSL
167+
*:Zone.Identifier

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
[![Publish Badge](https://github.com/tuunit/mkdocs-drawio/workflows/Publish/badge.svg)](https://github.com/tuunit/mkdocs-drawio/actions)
33
[![PyPI](https://img.shields.io/pypi/v/mkdocs-drawio)](https://pypi.org/project/mkdocs-drawio/)
44

5+
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.
56
[Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin)
67

7-
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)
8-
98
## Features
109
This plugin enables you to embed interactive drawio diagrams in your documentation. Simply add your diagrams like you would any other image:
1110

example/docs/configuration.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Configuration
2+
3+
## Diagram options
4+
5+
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.
6+
7+
```yaml
8+
plugins:
9+
- drawio:
10+
viewer_js: "https://viewer.diagrams.net/js/viewer-static.min.js"
11+
```
12+
13+
Further options are the following with their default value:
14+
15+
```yaml
16+
plugins:
17+
- drawio:
18+
# Control if hovering on a diagram shows a toolbar for zooming or not
19+
toolbar: true
20+
21+
# Control if tooltips will be shown (data-tooltips)
22+
tooltips: true
23+
24+
# Control if edit button will be shown in the lightbox view
25+
# (data-edit)
26+
edit: true
27+
28+
# Increase or decrease the padding around your diagrams
29+
# (data-border)
30+
border: 5
31+
```
32+
## HTML Attributes
33+
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:
34+
```markdown
35+
![](my-diagram.drawio){ data-toolbar-zoom="false" }
36+
```
37+
38+
To use these attributes you need to enable the markdown extension `attr_list` in your `mkdocs.yml`:
39+
40+
```yaml
41+
markdown_extensions:
42+
- attr_list
43+
```
44+
## Material Integration
45+
46+
If you are using the Material Theme and want to use the [instant-loading](https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=instant#instant-loading) feature. You will have to configure the following:
47+
48+
In your `mkdocs.yaml`:
49+
50+
```yaml
51+
theme:
52+
name: material
53+
features:
54+
- navigation.instant
55+
56+
plugins:
57+
- drawio
58+
59+
extra_javascript:
60+
- https://viewer.diagrams.net/js/viewer-static.min.js
61+
- javascripts/drawio-reload.js
62+
```
63+
64+
Add `docs/javascripts/drawio-reload.js` to your project:
65+
66+
```js
67+
document$.subscribe(({ body }) => {
68+
GraphViewer.processElements()
69+
})
70+
```

example/docs/index.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
# MkDocs Drawio Plugin Tests
1+
# MkDocs Plugin for embedding Drawio files
2+
3+
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.
4+
5+
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.
6+
[Buy Sergey a ☕](https://www.buymeacoffee.com/SergeyLukin)
7+
8+
## Installation
9+
10+
Install the plugin using pip or poetry:
11+
12+
```bash
13+
pip install mkdocs-drawio
14+
```
15+
16+
or
17+
18+
```bash
19+
poetry add mkdocs-drawio
20+
```
21+
22+
Then add the plugin to your `mkdocs.yml`:
23+
24+
```yaml
25+
plugins:
26+
- drawio
27+
```
28+
29+
## Features
30+
31+
The currently supported features are:
32+
33+
* Embed draw.io diagrams as normal markdown images in your documentation.
34+
* Use diagrams hosted within your own docs or external urls.
35+
* Support for multi page diagrams by selecting which page to display.
36+
* Compatible with `mkdocs-caption` and `mkdocs-glightbox`.
37+
* Print and edit button.
38+
39+
## Usage
40+
41+
42+
Simply add an image as you would normally do in markdown:
43+
44+
```markdown
45+
Absolute path:
46+
![](/assets/my-diagram.drawio)
47+
48+
Same directory as the markdown file:
49+
![](my-diagram.drawio)
50+
51+
Relative directory to the markdown file:
52+
![](../my-diagram.drawio)
53+
54+
55+
Or you can use external urls:
56+
![](https://example.com/diagram.drawio)
57+
```
58+
59+
Additionally this plugin supports multi page diagrams by using the `alt` text to select the pages by name:
60+
61+
```markdown
62+
![Page-2](my-diagram.drawio)
63+
![my-custom-page-name](my-diagram.drawio)
64+
```

example/docs/plumbing.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Plumbing and internals
2+
3+
For those who want to understand how the plugin works, here is a brief overview.
4+
5+
## Diagrams.net
6+
7+
**Diagrams.net** or **Draw.io** is a free online diagram software. It is great for creating diagrams, flowcharts, process diagrams, and more.
8+
9+
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
10+
11+
![](circle-square.drawio)
12+
13+
```xml
14+
<?xml version="1.0" encoding="UTF-8"?>
15+
<mxfile host="app.diagrams.net" version="26.0.7">
16+
<diagram name="Page-1" id="mV4jbraemd7C51ydpzk2">
17+
<mxGraphModel dx="565" dy="355" grid="1" gridSize="10"
18+
guides="1" tooltips="1" connect="1" arrows="1" fold="1"
19+
page="1" pageScale="1" pageWidth="394" pageHeight="394"
20+
math="0" shadow="0">
21+
<root>
22+
<mxCell id="0" />
23+
<mxCell id="1" parent="0" />
24+
<mxCell id="7JHgTfKEjFP575Ptm9la-1" value=""
25+
style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;"
26+
vertex="1" parent="1">
27+
<mxGeometry x="80" y="40" width="80" height="80" as="geometry" />
28+
</mxCell>
29+
<mxCell id="7JHgTfKEjFP575Ptm9la-2" value=""
30+
style="whiteSpace=wrap;html=1;aspect=fixed;
31+
fillColor=#f8cecc;strokeColor=#b85450;"
32+
vertex="1" parent="1">
33+
<mxGeometry x="180" y="40" width="80" height="80" as="geometry" />
34+
</mxCell>
35+
</root>
36+
</mxGraphModel>
37+
</diagram>
38+
</mxfile>
39+
```
40+
41+
## Plumbing
42+
43+
The plugin heavily relies on the Draw.io GraphViewer to render diagrams. The plugin itself is only responsible for replacing markdown references of drawio diagrams with the actual content of the files, passing configuration options to the viewer library and ensure compatibility across MkDocs themes.
44+
45+
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.
46+
47+
How the plugin processes diagrams:
48+
49+
1. mkdocs itself generates HTML for each markdown file in your docs.
50+
2. `mkdocs-drawio` then attaches to the `on_post_page` event. For more details, please have a look at the [event lifecycle documentation](https://www.mkdocs.org/dev-guide/plugins/#events)
51+
3. Adds the drawio viewer javascript reference
52+
4. Searches through the generated HTML for all `img` tags that reference a file with the extension `.drawio`
53+
5. Replaces the found `img` tags with `mxgraph` HTML block (actual drawio file content). For more details, please have a look at the [official drawio.com documentation](https://www.drawio.com/doc/faq/embed-html).
54+
55+
By default this plugin uses the [GraphViewer](https://github.com/jgraph/drawio/blob/dev/src/main/webapp/js/viewer-static.min.js) minified version.
56+
57+
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.
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
# Diagrams are not rendered in code blocks
1+
# Code Blocks
22

3-
```bash
3+
Diagrams are not rendered in code blocks.
4+
5+
## Example
6+
7+
```markdown
48
![test diagram](test.drawio)
59
```
10+
11+
## Markdown
12+
13+
```
14+
```markdown
15+
![test diagram](test.drawio)
16+
```
17+
```
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Error Handling
22

3-
You should see an invalid diagram below:
3+
In the following case the diagram is not valid should show an error message `Not a diagram file`.
4+
5+
## Example
46

57
![](test.drawio)
68

7-
You should see a warning in your mkdocs server similar to:
9+
10+
Additionnaly, you should see a warning in your MkDocs server similar to:
811

912
```bash
1013
WARNING - Warning: Found 0 results for page name 'test diagram' for diagram 'test.drawio' on path '/tmp/mkdocs_ce1qjhyn/test2'
1114
ERROR - Error: Provided diagram file 'test.drawio' on path '/tmp/mkdocs_ce1qjhyn/test5' is not a valid diagram
1215
```
16+
17+
## Markdown
18+
19+
```markdown
20+
![](test.drawio)
21+
```
22+
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
# Test to use url instead of file path
1+
# External URL
22

3-
![](http://127.0.0.1:8000/tests/assets/test.drawio)
3+
## Example
4+
This is an example of an external URL taken from jgraph:
5+
6+
![](https://raw.githubusercontent.com/jgraph/drawio-diagrams/dev/examples/gemfile-dependency-graph.drawio)
7+
8+
## Markdown
9+
10+
```markdown
11+
![](https://raw.githubusercontent.com/jgraph/drawio-diagrams/dev/examples/gemfile-dependency-graph.drawio)
12+
```
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Pagging
22

3-
Below you should see Page-1 (default) because the alt text is not found:
3+
## Examples
4+
5+
Below you should see diagram Page-1:
6+
![Page-1](test.drawio)
7+
8+
Below you should see diagram Page-2:
9+
![Page-2](test.drawio)
10+
11+
Below you should see Page-1 (default) because the specified Page-3 has not been found:
412
![test diagram](test.drawio)
513

614
Furthoremore, you should see a warning in your mkdocs server similar to:
715

816
```bash
9-
WARNING - Warning: Found 0 results for page name 'test diagram' for diagram 'test.drawio' on path '/tmp/mkdocs_ce1qjhyn/test2'
17+
WARNING - Warning: Found 0 results for page name 'Page-3' for diagram 'test.drawio' on path '/tmp/mkdocs_ce1qjhyn/test2'
1018
```
1119

12-
Below you should see diagram Page-1:
13-
![Page-1](test.drawio)
20+
## Markdown
1421

15-
Below you should see diagram Page-2:
22+
```markdown
23+
![Page-1](test.drawio)
1624
![Page-2](test.drawio)
25+
![Page-3](test.drawio)
26+
```

0 commit comments

Comments
 (0)