diff options
author | Phil Hughes <me@iamphill.com> | 2017-11-22 14:00:12 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-11-22 14:00:12 +0300 |
commit | d7527d73b17e41f949c609380aeffc837b80652e (patch) | |
tree | 8f465bb688d59063c85e9689241e65137cf6cc96 /app/assets/javascripts/render_mermaid.js | |
parent | 0efa7e24f22abd1dc04c165f31e7b77b0eb30ed4 (diff) | |
parent | 131e74d10dafbf2b781ab5d5517e42a18e20a587 (diff) |
Merge branch 'feature_add_mermaid' into 'master'
Add support of Mermaid
Closes #3711
See merge request gitlab-org/gitlab-ce!15107
Diffstat (limited to 'app/assets/javascripts/render_mermaid.js')
-rw-r--r-- | app/assets/javascripts/render_mermaid.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/assets/javascripts/render_mermaid.js b/app/assets/javascripts/render_mermaid.js new file mode 100644 index 00000000000..a253601f8e8 --- /dev/null +++ b/app/assets/javascripts/render_mermaid.js @@ -0,0 +1,30 @@ +// Renders diagrams and flowcharts from text using Mermaid in any element with the +// `js-render-mermaid` class. +// +// Example markup: +// +// <pre class="js-render-mermaid"> +// graph TD; +// A-- > B; +// A-- > C; +// B-- > D; +// C-- > D; +// </pre> +// + +import Flash from './flash'; + +$.fn.renderMermaid = function renderMermaid() { + if (this.length === 0) return; + + import(/* webpackChunkName: 'mermaid' */ 'blackst0ne-mermaid').then((mermaid) => { + mermaid.initialize({ + loadOnStart: false, + theme: 'neutral', + }); + + mermaid.init(undefined, this); + }).catch((err) => { + Flash(`Can't load mermaid module: ${err}`); + }); +}; |