Skip to content

Commit

Permalink
Update docs to use Mermaid 10.6.1 and update examples to use the same
Browse files Browse the repository at this point in the history
  • Loading branch information
facelessuser committed Nov 16, 2023
1 parent f488bb3 commit 8ca86fb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 55 deletions.
44 changes: 20 additions & 24 deletions docs/src/js/uml.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @param {string} className is the name of the class to target.
* @return {void}
*/
export default className => {
export default async className => {

// Custom element to encapsulate Mermaid content.
class MermaidDiv extends HTMLElement {
Expand Down Expand Up @@ -118,30 +118,26 @@ export default className => {
surrogate.appendChild(temp)

try {
mermaid.mermaidAPI.render(
`_diagram_${i}`,
getFromCode(parentEl),
(content, fn) => {
const el = document.createElement("div")
el.className = className
el.innerHTML = content
if (fn) {
fn(el)
}
const res = await mermaid.render(`_diagram_${i}`, getFromCode(parentEl), temp)
const content = res.svg
const fn = res.bindFunctions
const el = document.createElement("div")
el.className = className
el.innerHTML = content
if (fn) {
fn(el)
}

// Insert the render where we want it and remove the original text source.
// Mermaid will clean up the temporary element.
const shadow = document.createElement("diagram-div")
shadow.shadowRoot.appendChild(el)
block.parentNode.insertBefore(shadow, block)
parentEl.style.display = "none"
shadow.shadowRoot.appendChild(parentEl)
if (parentEl !== block) {
block.parentNode.removeChild(block)
}
},
temp
)
// Insert the render where we want it and remove the original text source.
// Mermaid will clean up the temporary element.
const shadow = document.createElement("diagram-div")
shadow.shadowRoot.appendChild(el)
block.parentNode.insertBefore(shadow, block)
parentEl.style.display = "none"
shadow.shadowRoot.appendChild(parentEl)
if (parentEl !== block) {
block.parentNode.removeChild(block)
}
} catch (err) {} // eslint-disable-line no-empty

if (surrogate.contains(temp)) {
Expand Down
49 changes: 24 additions & 25 deletions docs/src/markdown/extras/mermaid.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ and provide the configuration. We also have the custom loader that is runs when
end</code></pre>

<!-- Include Mermaid script and user config -->
<script src="https://unpkg.com/mermaid@9.4.0/dist/mermaid.min.js"></script>
<script src="https://unpkg.com/mermaid@10.6.1/dist/mermaid.min.js"></script>
<script>
window.mermaidConfig = {
startOnLoad: false,
Expand All @@ -356,7 +356,7 @@ window.mermaidConfig = {

/// tab | JS
```{.js .md-max-height}
const uml = className => {
const uml = async className => {

// Custom element to encapsulate Mermaid content.
class MermaidDiv extends HTMLElement {
Expand Down Expand Up @@ -434,7 +434,7 @@ const uml = className => {

// Find all of our Mermaid sources and render them.
const blocks = document.querySelectorAll(`pre.${className}, diagram-div`)
const surrogate = document.querySelector("html")
const surrogate = document.querySelector("html body")
for (let i = 0; i < blocks.length; i++) {
const block = blocks[i]
const parentEl = (block.tagName.toLowerCase() === "diagram-div") ?
Expand All @@ -453,27 +453,26 @@ const uml = className => {
surrogate.appendChild(temp)

try {
mermaid.mermaidAPI.render(
`_diagram_${i}`,
getFromCode(parentEl),
content => {
const el = document.createElement("div")
el.className = className
el.innerHTML = content

// Insert the render where we want it and remove the original text source.
// Mermaid will clean up the temporary element.
const shadow = document.createElement("diagram-div")
shadow.shadowRoot.appendChild(el)
block.parentNode.insertBefore(shadow, block)
parentEl.style.display = "none"
shadow.shadowRoot.appendChild(parentEl)
if (parentEl !== block) {
block.parentNode.removeChild(block)
}
},
temp
)
const res = await mermaid.render(`_diagram_${i}`, getFromCode(parentEl), temp)
const content = res.svg
const fn = res.bindFunctions
const el = document.createElement("div")
el.className = className
el.innerHTML = content
if (fn) {
fn(el)
}

// Insert the render where we want it and remove the original text source.
// Mermaid will clean up the temporary element.
const shadow = document.createElement("diagram-div")
shadow.shadowRoot.appendChild(el)
block.parentNode.insertBefore(shadow, block)
parentEl.style.display = "none"
shadow.shadowRoot.appendChild(parentEl)
if (parentEl !== block) {
block.parentNode.removeChild(block)
}
} catch (err) {} // eslint-disable-line no-empty

if (surrogate.contains(temp)) {
Expand Down Expand Up @@ -507,7 +506,7 @@ markdown_extensions:

extra_javascript:
- optionalConfig.js
- https://unpkg.com/mermaid@9.4.0/dist/mermaid.min.js
- https://unpkg.com/mermaid@10.6.1/dist/mermaid.min.js
- extra-loader.js
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extra_css:
# - https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.css
- assets/pymdownx-extras/extra.css
extra_javascript:
- https://unpkg.com/mermaid@9.4.0/dist/mermaid.min.js
- https://unpkg.com/mermaid@10.6.1/dist/mermaid.min.js
# - https://cdn.jsdelivr.net/npm/katex@0.13.18/dist/katex.min.js
- https://polyfill.io/v3/polyfill.min.js?features=es6
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
Expand Down
2 changes: 2 additions & 0 deletions docs/theme/assets/pymdownx-extras/extra-loader-MCFnu0Wd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8ca86fb

Please sign in to comment.