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 all 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -26,7 +26,8 @@
"codeBlockWrapButtons",
"web3Form",
"codeBlockCopyButtons",
"dataTable"
"dataTable",
"mermaid"
],
"pluginsContext" : {
"filterTags" : {
Expand Down
112 changes: 112 additions & 0 deletions docs/userGuide/plugins/mermaid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
### Plugin: Mermaid

<div id="content">

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 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.

```js {heading="site.json"}
{
...
"plugins": [
"mermaid"
]
}
```

<panel header="Optional: Specify an alternative URL to load the Mermaid code">

By default, the plugin loads the Mermaid code from a CDN URL. However, you can optionally specify an alternative URL to load the Mermaid code from a different source.

```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
}
}
}
```

</panel>

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.
<div>
5 changes: 5 additions & 0 deletions docs/userGuide/syntax/diagrams.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Diagrams

### PlantUML Diagrams
You can use the [PlantUML](http://plantuml.com/) syntax to add diagrams.

<box type="warning">
Expand Down Expand Up @@ -159,3 +160,7 @@ bob -> bob ++ : self call
<include src="diagrams.md#puml-examples" />

</div>

### Mermaid Diagrams

<include src="{{ baseUrl }}/userGuide/plugins/mermaid.md#content" />
1 change: 1 addition & 0 deletions docs/userGuide/usingPlugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ MarkBind has a set of built-in plugins that can be used immediately without inst
<include src="plugins/mathDelimiters.md" />
<include src="plugins/web3Form.md" />
<include src="plugins/dataTable.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
13 changes: 13 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,18 @@ <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', () => {
mermaid.initialize({});
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
13 changes: 13 additions & 0 deletions packages/cli/test/functional/test_site/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -945,5 +945,18 @@ <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', () => {
mermaid.initialize({});
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 @@ -468,6 +468,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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
13 changes: 13 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,18 @@ <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', () => {
mermaid.initialize({});
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,18 @@ <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', () => {
mermaid.initialize({});
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,18 @@
})
}
</script>
<script type="module">
import mermaid from 'https://unpkg.com/mermaid@10/dist/mermaid.esm.min.mjs';
document.addEventListener('DOMContentLoaded', () => {
mermaid.initialize({});
Vue.directive('mermaid', {
inserted: function(el) {
mermaid.run({
nodes: [el]
});
}
});
});
</script>

</html>
Loading
Loading