-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplantuml.html
More file actions
30 lines (26 loc) · 1.28 KB
/
plantuml.html
File metadata and controls
30 lines (26 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{% if page.plantuml %}
<script src="//cdn.jsdelivr.net/npm/plantuml-encoder@1/dist/plantuml-encoder.min.js"></script>
<script>
const umlTags = document.querySelectorAll('plantuml');
umlTags.forEach((umlTag) => {
// innerHTML gets a serialization of the nested child DOM elements, which returns angle
// brackets that are not part of a tag as their HTML entities. Therefore, we need to undo
// that. However, this also replaces any literal '<' and '>' with the corresponding
// angle brackets.
const plantuml = umlTag.innerHTML.replaceAll("<", "<").replaceAll(">", ">");
const imgTag = document.createElement("img");
imgTag.src = "//www.plantuml.com/plantuml/svg/" + window.plantumlEncoder.encode(plantuml);
if (umlTag.dataset.alt) {
imgTag.alt = umlTag.dataset.alt;
}
const figureTag = document.createElement("figure");
figureTag.appendChild(imgTag);
if (umlTag.dataset.caption) {
const captionTag = document.createElement("figcaption");
captionTag.appendChild(document.createTextNode(umlTag.dataset.caption));
figureTag.appendChild(captionTag);
}
umlTag.parentNode.replaceChild(figureTag, umlTag);
});
</script>
{% endif %}