Skip to content

Commit 2d1474f

Browse files
Added Mermaid support (#649)
1 parent 71d5980 commit 2d1474f

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

_config.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,16 @@ pdf:
853853
# CDNJS, provided by cloudflare, maybe the best CDN, but not works in China
854854
#cdn: //cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js
855855

856+
# Mermaid tag
857+
mermaid:
858+
enable: false
859+
# Available themes: default | dark | forest | neutral
860+
theme: forest
861+
# Use 8.0.0 as default, jsdelivr as default CDN, works everywhere even in China
862+
cdn: //cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js
863+
# CDNJS, provided by cloudflare, maybe the best CDN, but not works in China
864+
#cdn: //cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js
865+
856866

857867
#! ---------------------------------------------------------------
858868
#! DO NOT EDIT THE FOLLOWING SETTINGS
@@ -879,16 +889,16 @@ motion:
879889
sidebar: slideUpIn
880890

881891
# Fancybox. There is support for old version 2 and new version 3.
882-
# Choose only any one variant, do not need to install both.
892+
# Choose only one variant, do not need to install both.
883893
# To install 2.x: https://github.com/theme-next/theme-next-fancybox
884894
# To install 3.x: https://github.com/theme-next/theme-next-fancybox3
885895
fancybox: false
886896

887-
# Added switch option for separated repo in 6.0.0.
897+
# Polyfill to remove click delays on browsers with touch UIs.
888898
# Dependencies: https://github.com/theme-next/theme-next-fastclick
889899
fastclick: false
890900

891-
# Added switch option for separated repo in 6.0.0.
901+
# Vanilla JavaScript plugin for lazyloading images.
892902
# Dependencies: https://github.com/theme-next/theme-next-jquery-lazyload
893903
lazyload: false
894904

layout/_layout.swig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
{% include '_third-party/analytics/firestore.swig' %}
111111
{% include '_third-party/math/index.swig' %}
112112
{% include '_third-party/pdf.swig' %}
113+
{% include '_third-party/mermaid.swig' %}
113114
{% include '_third-party/baidu-push.swig' %}
114115
{% include '_third-party/schedule.swig' %}
115116
{% include '_third-party/needsharebutton.swig' %}

layout/_third-party/mermaid.swig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if theme.mermaid.enable %}
2+
<script>
3+
if ($('body').find('pre.mermaid').length) {
4+
$.ajax({
5+
type: 'GET',
6+
url: '{{ theme.mermaid.cdn }}',
7+
dataType: 'script',
8+
cache: true,
9+
success: function() {
10+
mermaid.initialize({
11+
theme: '{{ theme.mermaid.theme }}',
12+
logLevel: 3,
13+
flowchart: { curve: 'linear' },
14+
gantt: { axisFormat: '%m/%d/%Y' },
15+
sequence: { actorMargin: 50 }
16+
});
17+
}
18+
});
19+
}
20+
</script>
21+
{% endif %}

scripts/tags/mermaid.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* mermaid.js | https://theme-next.org/docs/tag-plugins/mermaid/
3+
*/
4+
5+
/* global hexo */
6+
7+
'use strict';
8+
9+
function mermaid(args, content) {
10+
return `<pre class="mermaid" style="text-align: center;">
11+
${args.join(' ')}
12+
${content}
13+
</pre>`;
14+
}
15+
16+
hexo.extend.tag.register('mermaid', mermaid, {ends: true});

source/js/src/js.cookie.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
66
* Released under the MIT license
77
*/
8+
89
;(function (factory) {
910
var registeredInModuleLoader = false;
1011
if (typeof define === 'function' && define.amd) {

0 commit comments

Comments
 (0)