Skip to content
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

Add Mermaid Plugin #2475

Merged
merged 37 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a9a873b
Add mermaid plugin
Mar 25, 2024
a22da8e
Improve code quality
Mar 25, 2024
968378b
Improve code quality
Mar 25, 2024
a818c5c
Merge branch 'master' into mermaid
Apr 1, 2024
5baf061
Add unit test
Apr 1, 2024
1d48418
Add functional test
Apr 1, 2024
3b19e31
Add documentation
Apr 1, 2024
1f9a752
Enhance functional test with inside panel option
Apr 1, 2024
6358354
Update test expected
Apr 1, 2024
fa53f12
Merge branch 'master' into mermaid
Apr 5, 2024
e7d6d4d
Improve documentation
Apr 5, 2024
fb21d00
Merge master
Apr 12, 2024
6658892
Fix code issues
Apr 12, 2024
713a4d1
Update functional code
Apr 13, 2024
0736424
Update unit test
Apr 13, 2024
c2fa86c
Merge branch 'master' into mermaid
Apr 13, 2024
edc199a
Merge branch 'master' into mermaid
Tim-Siu Apr 15, 2024
c4bfb0c
Merge branch 'master' into mermaid
Tim-Siu Apr 17, 2024
0577836
Switch to Async loading of script
Apr 17, 2024
226f503
Update testcases
Apr 17, 2024
5803613
Update testcases
Apr 17, 2024
6a0f331
Fix broken link
Apr 17, 2024
a3ac59d
Merge branch 'master' into mermaid
Tim-Siu Apr 19, 2024
10441c0
Polish documentation
Apr 19, 2024
1d3cf98
Revert async loading of mermaid script
Apr 19, 2024
a63d674
Update functional test
Apr 19, 2024
fc6da44
Update functional test
Apr 19, 2024
f5d0c0a
Improve documentation
Apr 21, 2024
c0a1488
Enhance functional test to cover inclusion
Apr 21, 2024
3186303
Update expected
Apr 21, 2024
3265bb7
Minor update to syntax
Apr 21, 2024
6df7858
Update functional test
Apr 21, 2024
fd2c69c
Merge branch 'master' into mermaid
Tim-Siu Apr 21, 2024
2bf16fe
Fix typo
Apr 21, 2024
ca91a02
Fix typo
Apr 21, 2024
392b756
Fix nits
yucheng11122017 Apr 22, 2024
c6c869b
fix nits
yucheng11122017 Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"mathDelimiters",
"codeBlockWrapButtons",
"web3Form",
"codeBlockCopyButtons"
"codeBlockCopyButtons",
"mermaid"
],
"pluginsContext" : {
"filterTags" : {
Expand Down
96 changes: 96 additions & 0 deletions docs/userGuide/plugins/mermaid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
### Plugin: Mermaid

This plugin allows you to utilize [Mermaid](https://mermaid-js.github.io/mermaid/) by automatically importing the library and initializing the rendering of the diagrams.

> Mermaid is a JavaScript based diagramming and charting tool that renders Markdown-inspired text definitions to create and modify diagrams dynamically.

<box type="info">

All supported diagrams and detailed configurations are available in [the Mermaid official documentation](https://mermaid-js.github.io/mermaid/).

</box>

To enable this plugin, add `mermaid` to your site's plugins. Optionally, you can specify an alternative URL to load the Mermaid code in the plugin context.

```js {heading="site.json"}
{
...
"plugins": [
"mermaid"
],
"pluginsContext": {
"mermaid": {
"address": "https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs" // replace with URL of your choice
yucheng11122017 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
```

If no `address` is specified in the plugin context, the default CDN address (`https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs`) will be used.

To create a Mermaid diagram, use the `<mermaid>` tag and provide the diagram definition within the tag.

{{ icon_example }} Pie Chart:

<include src="codeAndOutput.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="code">
<mermaid>
pie title Pets adopted by volunteers
"Dogs" : 386
"Cats" : 85
"Rats" : 15
</mermaid>
</variable>
</include>

{{ icon_example }} Flowchart:

<include src="codeAndOutput.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="code">
<mermaid>
flowchart TD
A[Start] --> B{Is it?}
B -->|Yes| C[OK]
C --> D[Rethink]
D --> B
B ---->|No| E[End]
</mermaid>
</variable>
</include>

{{ icon_example }} User Journey Diagram:

<include src="codeAndOutput.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="code">
<mermaid>
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
</mermaid>
</variable>
</include>

{{ icon_example }} Gitgraph Diagram:

<include src="codeAndOutput.md" boilerplate >
<variable name="highlightStyle">html</variable>
<variable name="code">
<mermaid>
gitGraph
commit
branch develop
checkout develop
commit
checkout main
merge develop
</mermaid>
</variable>
</include>

The plugin automatically converts the `<mermaid>` tags into appropriate `<div>` elements with the necessary classes and attributes for rendering the diagrams using the Mermaid library.
5 changes: 5 additions & 0 deletions docs/userGuide/syntax/diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ name | `string` | The name of the output file.<br>Avoid using the same name fo
src | `string` | The URL of the diagram if your diagram is in another `.puml` file.<br>The URL can be specified as absolute or relative references. More info in: _[Intra-Site Links]({{baseUrl}}/userGuide/formattingContents.html#intraSiteLinks)_
width | `string` | The width of the diagram in pixels.<br>If both width and height are specified, width takes priority over height. It is to maintain the diagram's aspect ratio.

<box type="tip">

It's also possible to utilize JavaScript diagram libraries such as [Mermaid](https://mermaid-js.github.io/mermaid/) via the [Mermaid plugin](../usingPlugins.html#plugin-mermaid).
Tim-Siu marked this conversation as resolved.
Show resolved Hide resolved
</box>

<div id="short" class="d-none">

```
Expand Down
1 change: 1 addition & 0 deletions docs/userGuide/usingPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ MarkBind has a set of built-in plugins that can be used immediately without inst
<include src="plugins/disqus.md" />
<include src="plugins/mathDelimiters.md" />
<include src="plugins/web3Form.md" />
<include src="plugins/mermaid.md" />

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary new line

## Using External Plugins

Expand Down
12 changes: 12 additions & 0 deletions packages/cli/test/functional/test_site/expected/bugs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
12 changes: 12 additions & 0 deletions packages/cli/test/functional/test_site/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -934,5 +934,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
6 changes: 6 additions & 0 deletions packages/cli/test/functional/test_site/expected/siteData.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,12 @@
"h1-text": "\n\n\n h1 text\n \n"
},
"headingKeywords": {}
},
{
"src": "testMermaid.md",
"title": "Rendering of diagrams via mermaid-js",
"headings": {},
"headingKeywords": {}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
12 changes: 12 additions & 0 deletions packages/cli/test/functional/test_site/expected/testAnnotate.html
Original file line number Diff line number Diff line change
Expand Up @@ -456,5 +456,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,17 @@ <h1 id="heading-in-footer-should-not-be-indexed">Heading in footer should not be
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>