Skip to content

Commit 7db460e

Browse files
author
Laurent Franceschetti
committed
Update documentation and bump to new version
1 parent e48544e commit 7db460e

File tree

10 files changed

+345
-211
lines changed

10 files changed

+345
-211
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 1.1.0, 2023-09-01
8+
9+
Added: Parameter `javascript` in config file for optionally specifying the
10+
URL or path of the Mermaid javascript library.
11+
12+
Changed: Parameter `extra_javascript` in config file is DEPRECATED,
13+
for optionally specifying the URL or path of the Mermaid javascript library
14+
15+
Changed: Updated documentation.
16+
717
## 1.0.8, 2023-08-09
818

919
Fixed: Arguments of config file not taken into consideration,

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# mkdocs-mermaid2-plugin
1+
<div align="center">
2+
3+
# Mkdocs-Mermaid2
24

35

46
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
@@ -7,9 +9,11 @@
79
![Downloads(PyPI)](https://img.shields.io/pypi/dm/mkdocs-mermaid2-plugin)
810

911

10-
An [MkDocs](https://www.mkdocs.org/) plugin that renders textual graph
11-
descriptions into [Mermaid](https://mermaid-js.github.io/mermaid) graphs
12-
(flow charts, sequence diagrams, pie charts, etc.).
12+
An [MkDocs](https://www.mkdocs.org/) plugin that renders [Mermaid](https://mermaid-js.github.io/mermaid) text descriptions into diagrams (flow charts, sequence diagrams, pie charts, etc.).
13+
14+
</div>
15+
16+
---
1317

1418
* **See the [mkdocs-mermaid2 documentation on Read The Docs](https://mkdocs-mermaid2.readthedocs.io).**
1519
* See the [package on Pypi](https://pypi.org/project/mkdocs-mermaid2-plugin/).
@@ -26,15 +30,17 @@ markdown-toc -i README.md
2630

2731
<!-- toc -->
2832

29-
- [Introduction](#introduction)
30-
- [Installation](#installation)
31-
* [Automatic](#automatic)
32-
* [Manual](#manual)
33-
* [Test](#test)
34-
- [Configuration](#configuration)
35-
* [Basic configuration](#basic-configuration)
36-
* [Specifying the version of the Mermaid library](#specifying-the-version-of-the-mermaid-library)
37-
- [For more information](#for-more-information)
33+
- [Mkdocs-Mermaid2](#mkdocs-mermaid2)
34+
- [Introduction](#introduction)
35+
- [Installation](#installation)
36+
- [Automatic](#automatic)
37+
- [Manual](#manual)
38+
- [Test](#test)
39+
- [Configuration](#configuration)
40+
- [Basic configuration](#basic-configuration)
41+
- [Specifying the version of the Mermaid library](#specifying-the-version-of-the-mermaid-library)
42+
- [Additional settings for the Material theme](#additional-settings-for-the-material-theme)
43+
- [For more information](#for-more-information)
3844

3945
<!-- tocstop -->
4046

mermaid2/plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
# ------------------------
1717
# Constants and utilities
1818
# ------------------------
19-
# the default (recommended) mermaid lib
20-
JAVASCRIPT_VERSION = '10.1.0'
19+
# the default (recommended) mermaid lib:
20+
JAVASCRIPT_VERSION = '10.4.0'
2121
JAVASCRIPT_PRE_10 = "https://unpkg.com/mermaid@%s/dist/mermaid.min.js"
22+
# New format (ESM):
2223
JAVASCRIPT = "https://unpkg.com/mermaid@%s/dist/mermaid.esm.min.mjs"
2324

2425

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33

4-
VERSION = '1.0.9'
4+
VERSION = '1.1.0'
55

66
# required if you want to run tests
77
# pip install 'mkdocs-mermaid2-plugin[test]'

webdoc/docs/description.md

Lines changed: 75 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
1+
# Detailed description of the page production process
2+
13
## Steps for the preparation of an HTML page
24

3-
There are three steps in the preparation of the page:
5+
There are three steps in the preparation of the HTML page:
46

5-
1. Setting up the HTML code that wraps the diagram.
6-
2. Inserting the javascript library (Mermaid.js) into the HTML page
7-
3. Inserting the call to the library
7+
```mermaid
8+
flowchart TD
9+
subgraph Page [Page production]
10+
HTML(1. Setting up the HTML tags around the diagram.) --> JS("2. Inserting the call to Mermaid.js")
11+
JS --> Init(3. Initialization/customization)
12+
end
813
9-
## Conversion to HTML
14+
```
1015

11-
When converting the markdown into HTML, mkdocs normally inserts the
12-
Mermaid code (text) describing the diagram
13-
into segments:
16+
When the webserver serves the statig html page,
17+
the Mermaid.js library is executed in the user's browser, to render the diagram.
1418

15-
<pre class="mermaid">
16-
<code>
17-
...
18-
</code>
19-
</pre>
19+
## Conversion to HTML
2020

21+
When converting the markdown into HTML, MkDocs normally inserts the
22+
Mermaid code (text) describing the diagram
23+
into segments, which will then be processed by the Mermaid.js library
24+
(in the user's browser):
25+
26+
```html
27+
<pre class="mermaid">
28+
<code>
29+
...
30+
</code>
31+
</pre>
32+
```
2133

22-
To make the HTML/css page more robust for most mkdocs themes,
23-
the mermaid plugin systematically converts
34+
To make the HTML/css page more robust for most MkDocs themes,
35+
the Mkdocs-Mermaid2 plugin systematically converts
2436
those segments directly into `<div>` elements:
2537

26-
<div class="mermaid">
27-
...
28-
</div>
38+
```html
39+
<div class="mermaid">
40+
...
41+
</div>
42+
```
2943

3044
!!! Note "Superfences extension"
3145
The principle remains the same
32-
when using the [Superfences](superfences) extension, except
33-
when using the Material theme.
46+
when using the [Superfences](superfences) extension.
3447

35-
That extension is **not** mandatory.
48+
That extension is **not** mandatory, except
49+
when using the Material theme.
3650

37-
## Insertion of the Javascript Library
51+
## Automatic insertion of the Javascript Library
3852
The plugin then inserts a call to the
3953
[javascript library](https://github.com/mermaid-js/mermaid).
4054

@@ -48,49 +62,71 @@ of Mermaid.js required:
4862
version: '10.1.0'
4963
```
5064
51-
5265
!!! Note
53-
The behavior of the plugin depends of the version of Mermaid.js, because
54-
version 10.0.0 represents a significant change ([see changelog](https://github.com/mermaid-js/mermaid/blob/develop/CHANGELOG.md#1000)).
66+
Mkdocs-Macros inserts the Mermaid.js library into the HTML page
67+
**only** when a Mermaid diagram is detected in the markdown page.
5568
56-
=== "Mermaid.js > 10.0.0"
69+
!!! Warning "Change of distribution format"
70+
The behavior of the plugin depends of the version of Mermaid.js.
5771
58-
> *From version 1.0 of mkdocs-mermaid2*
72+
[As of version 10 of the Mermaid javascript library, the plugin uses the ESM format for distribution](https://github.com/mermaid-js/mermaid/releases/tag/v10.0.0) (see also the [changelog](https://github.com/mermaid-js/mermaid/blob/develop/CHANGELOG.md#1000)).
5973
60-
[For versions from 10.0.0 of the Mermaid javascript library, the plugin uses the ESM format](https://github.com/mermaid-js/mermaid/releases/tag/v10.0.0), since
61-
it is the only one available. This requires a specific call from the HTML
74+
More information can be found on [ECMAScript Module](https://nodejs.org/api/esm.html#modules-ecmascript-modules)
75+
(or **ESM**), but for our purposes:
76+
77+
1. **The main file is recognizable because it has the `.mjs` extension.**
78+
2. The HTML call must have the form: `<script src="<URL>", type="module">`
79+
3. A module in ESM format is not a single file, but a hierarchy of directories/files.
80+
81+
**MkDocs-Mermaid2, as of version 1.0, takes this difference into account.**
82+
83+
=== "ESM Library"
84+
85+
> For versions of MkDocs-Mermaid2 >= 1 and versions of Mermaid2.js >= 10
86+
87+
This requires a specific call from the HTML
6288
page e.g.:
6389

6490
``` html
6591
<script src="https://unpkg.com/mermaid@10.0.2/dist/mermaid.esm.min.mjs" type="module">
6692
</script>
6793
```
6894

69-
7095
The plugin automatically inserts this call.
7196

72-
=== "Earlier versions"
97+
=== "All-in-one Library"
7398

7499
For an earlier version of the Mermaid.js (<10),
75-
the plugin uses the traditional call
76-
from HTML:
100+
the plugin continues to use the traditional version, which is an **all-in-one file**.
101+
102+
Those library files are recognizable because they have the `.js` extension.
103+
104+
The call in the HTML page is:
77105

78106
``` html
79107
<script src="https://unpkg.com/mermaid@8.8.2/dist/mermaid.min.js">
80108
mermaid.initialize()
81109
</script>
82110
```
83111

112+
84113
The plugin automatically inserts this call.
85114

115+
** This is still a valid method.** (Even though the very first versions after 10.0.0 no longer provided
116+
this file, later versions have resumed providing it.)
86117

87-
## Call to the Library
118+
119+
120+
121+
## Initialization sequence
88122

89123
### Default sequence
90124
To start displaying of the diagrams, the plugin then automatically inserts
91125
a separate call to initialize the Mermaid library:
92126

93-
127+
```javascript
128+
mermaid.initialize()
129+
```
94130

95131
The user's browser will then read this code and render it on the fly.
96132

@@ -124,10 +160,10 @@ plugins:
124160

125161
The plugin then automatically adds the initialization sequence:
126162

127-
=== "mermaid.js >= 10.0"
163+
=== "ESM modules"
128164

129165
Both `import` and `mermaid.initialize()` must be in the same `<script>`
130-
tag.
166+
tag. This is the code produced by the plugin:
131167

132168
```html
133169
<script type="module">import mermaid from "https://unpkg.com/mermaid@10.1.0/dist/mermaid.esm.min.mjs";
@@ -144,9 +180,9 @@ The plugin then automatically adds the initialization sequence:
144180
});
145181
</script>
146182
```
147-
=== "Earlier versions"
183+
=== "Traditional modules"
148184

149-
For versions of mermaid.js < 10, **two** calls to the `<script>` tag are required.
185+
For traditional (all-in-one file) javascript modules, **two** calls to the `<script>` tag are required. This is the code produced by the plugin:
150186

151187
```html
152188
<script src="https://unpkg.com/mermaid@9.1.0/dist/mermaid.min.js"></script>

webdoc/docs/index.md

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
# Mermaid2: A diagrams plugin for Mkdocs
1+
# Mkdocs-Mermaid2<br>A diagrams plugin for Mkdocs { align=center }
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
---
4+
5+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
46
[![PyPI](https://img.shields.io/pypi/v/mkdocs-mermaid2-plugin)](https://pypi.org/project/mkdocs-mermaid2-plugin/)
57
![Github](https://img.shields.io/github/v/tag/fralau/mkdocs-mermaid2-plugin?label=github%20tag)
68
![Downloads(PyPI)](https://img.shields.io/pypi/dm/mkdocs-mermaid2-plugin)
79

10+
811
## Introduction
9-
**Mermaid2** is a plugin for the [MkDocs](https://www.mkdocs.org/)
12+
**Mkdocs-Mermaid2** is a plugin for the [MkDocs](https://www.mkdocs.org/)
1013
static sites generator, which allows you
11-
to render Mermaid diagrams inserted in the markdown pages.
14+
to render Mermaid diagrams inserted (as text) into the markdown pages.
1215

1316
- [The official repository of Mermaid2 is on github.](https://github.com/fralau/mkdocs-mermaid2-plugin)
1417
- [Mermaid2 is available from Pypi.](https://pypi.org/project/mkdocs-mermaid2-plugin/)
@@ -153,6 +156,47 @@ plugins:
153156
If you declare plugins in the config file, you need to declare _all_ of them,
154157
including `search` (which would otherwise have been installed by default.)
155158

159+
160+
161+
162+
### Specifying the version of the Mermaid library
163+
164+
By default, the plugin selects a version of the Mermaid javascript library
165+
that is known to work (some versions work better than others).
166+
167+
You may specify a different version of the Mermaid library, like so:
168+
169+
```yaml
170+
plugins:
171+
- search
172+
- mermaid2:
173+
version: 10.0.2
174+
```
175+
176+
The plugin will insert the correct call to the javascript library
177+
inside the final HTML page.
178+
179+
180+
### Specifying your own Mermaid library
181+
182+
By default, mkdocs-mermaid2 automatically inserts the proper calls to
183+
Mermaid.js (according to the correct version),
184+
so that the diagrams are correctly interpreted.
185+
186+
You may, however, specify your own explicit call:
187+
188+
```yaml
189+
plugins:
190+
- search
191+
- mermaid2:
192+
javascript: https://unpkg.com/mermaid@10.4.0/dist/mermaid.esm.min.mjs
193+
```
194+
195+
For more details, [see the relative page](../library).
196+
197+
198+
199+
156200
### Use of the Material theme
157201

158202
!!! Note
@@ -210,52 +254,6 @@ The result would be as follows, for the diagrams above:
210254

211255

212256

213-
### Specifying the version of the Mermaid library
214-
215-
By default, the plugin selects a version of the Mermaid javascript library
216-
that is known to work (some versions work better than others).
217-
218-
You may specify a different version of the Mermaid library, like so:
219-
220-
```yaml
221-
plugins:
222-
- search
223-
- mermaid2:
224-
version: 10.0.2
225-
```
226-
227-
The plugin will insert the correct call to the javascript library
228-
inside the final HTML page.
229-
230-
231-
### Specifying your own Mermaid library
232-
233-
By default, mkdocs-mermaid2 automatically inserts the proper calls to
234-
Mermaid.js (according to the correct version),
235-
so that the diagrams are correctly interpreted.
236-
237-
You may, however, specify your own call, with the use of the `extra_javascript`
238-
directive in the configuration file. **This is considered as a hack,
239-
if the default procedure doesn't work.**
240-
241-
If you do that, then the plugin will refrain from inserting its own call
242-
to the Mermaid.js.
243-
244-
```yaml
245-
extra_javascript:
246-
- https://unpkg.com/mermaid@8.8.2/dist/mermaid.min.js
247-
```
248-
249-
250-
251-
!!! Warning
252-
To make this work with versions of the library > 10
253-
with the `mjs` extension, you need a version of mkdocs > 1.5.0.
254-
255-
With versions of mkdocs < 1.5.0,
256-
see the [troubleshooting section](troubleshooting/#explicit-calls-of-the-mermaid-library).
257-
258-
259257
### Testing
260258

261259
To test your website with a diagram, restart the mkdocs server:

0 commit comments

Comments
 (0)