Skip to content

Commit

Permalink
Added Mermaid support (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Mar 7, 2019
1 parent 71d5980 commit 2d1474f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
16 changes: 13 additions & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,16 @@ pdf:
# CDNJS, provided by cloudflare, maybe the best CDN, but not works in China
#cdn: //cdnjs.cloudflare.com/ajax/libs/pdfobject/2.1.1/pdfobject.min.js

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


#! ---------------------------------------------------------------
#! DO NOT EDIT THE FOLLOWING SETTINGS
Expand All @@ -879,16 +889,16 @@ motion:
sidebar: slideUpIn

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

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

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

Expand Down
1 change: 1 addition & 0 deletions layout/_layout.swig
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
{% include '_third-party/analytics/firestore.swig' %}
{% include '_third-party/math/index.swig' %}
{% include '_third-party/pdf.swig' %}
{% include '_third-party/mermaid.swig' %}
{% include '_third-party/baidu-push.swig' %}
{% include '_third-party/schedule.swig' %}
{% include '_third-party/needsharebutton.swig' %}
Expand Down
21 changes: 21 additions & 0 deletions layout/_third-party/mermaid.swig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% if theme.mermaid.enable %}
<script>
if ($('body').find('pre.mermaid').length) {
$.ajax({
type: 'GET',
url: '{{ theme.mermaid.cdn }}',
dataType: 'script',
cache: true,
success: function() {
mermaid.initialize({
theme: '{{ theme.mermaid.theme }}',
logLevel: 3,
flowchart: { curve: 'linear' },
gantt: { axisFormat: '%m/%d/%Y' },
sequence: { actorMargin: 50 }
});
}
});
}
</script>
{% endif %}
16 changes: 16 additions & 0 deletions scripts/tags/mermaid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* mermaid.js | https://theme-next.org/docs/tag-plugins/mermaid/
*/

/* global hexo */

'use strict';

function mermaid(args, content) {
return `<pre class="mermaid" style="text-align: center;">
${args.join(' ')}
${content}
</pre>`;
}

hexo.extend.tag.register('mermaid', mermaid, {ends: true});
1 change: 1 addition & 0 deletions source/js/src/js.cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
* Released under the MIT license
*/

;(function (factory) {
var registeredInModuleLoader = false;
if (typeof define === 'function' && define.amd) {
Expand Down

0 comments on commit 2d1474f

Please sign in to comment.