Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-12-20 16:48:09 +0300
committerDouwe Maan <douwe@selenight.nl>2018-01-05 17:53:07 +0300
commit288b276077987bc77f191d2cb93eb2f764c5c1ef (patch)
treefe41897661fdb8754fe12edffa6ee31e009d0705 /app/assets/javascripts/render_mermaid.js
parent58a705aaacfb137d654e5f1313c9e5f898422eed (diff)
Copy Mermaid graphs as GFM
Diffstat (limited to 'app/assets/javascripts/render_mermaid.js')
-rw-r--r--app/assets/javascripts/render_mermaid.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/app/assets/javascripts/render_mermaid.js b/app/assets/javascripts/render_mermaid.js
index 41942c04a4e..b7cde6fb092 100644
--- a/app/assets/javascripts/render_mermaid.js
+++ b/app/assets/javascripts/render_mermaid.js
@@ -24,7 +24,25 @@ export default function renderMermaid($els) {
});
$els.each((i, el) => {
- mermaid.init(undefined, el);
+ const source = el.textContent;
+
+ mermaid.init(undefined, el, (id) => {
+ const svg = document.getElementById(id);
+
+ svg.classList.add('mermaid');
+
+ // pre > code > svg
+ svg.closest('pre').replaceWith(svg);
+
+ // We need to add the original source into the DOM to allow Copy-as-GFM
+ // to access it.
+ const sourceEl = document.createElement('text');
+ sourceEl.classList.add('source');
+ sourceEl.setAttribute('display', 'none');
+ sourceEl.textContent = source;
+
+ svg.appendChild(sourceEl);
+ });
});
}).catch((err) => {
Flash(`Can't load mermaid module: ${err}`);