This commit is contained in:
18218461270@163.com 2025-08-20 20:30:23 +08:00
parent b319a665b2
commit 1e5bdba412
2 changed files with 14 additions and 14 deletions

View File

@ -2,7 +2,7 @@
/* global hexo */
const mermaid = require('./mermaid.js');
const mermaid = require('./lib/mermaid.js');
hexo.config.mermaid = Object.assign({
mmdcPath: 'mmdc',
@ -11,9 +11,9 @@ hexo.config.mermaid = Object.assign({
width: 800,
height: 600,
format: 'svg',
background: 'white',
background: 'transparent',
scale: 1
},
hexo.config.mermaid);
hexo.extend.tag.register('mermaid', mermaid(hexo.config.mermaid), { ends = true });
hexo.extend.tag.register('mermaid', mermaid(hexo.config.mermaid), { ends: true });

View File

@ -6,28 +6,28 @@ function mermaid(config) {
return function(args, content) {
let options = Object.assign({}, config);
let caption = '';
for (const arg in args) {
args.forEach(arg => {
const arr = arg.split(':');
if (arr.length == 1) {
caption = arr;
} else {
const { key, val } = arr;
const [ key, val ] = arr;
options[key] = val;
}
}
});
const args = [
'-t', options.theme || 'default',
'-w', options.width || 800,
'-H', options.height || 600,
'-e', options.format || 'svg',
'-b', options.background || 'white',
'-s', options.scale || 1,
const mmdcArgs = [
'-t', options.theme,
'-w', options.width,
'-H', options.height,
'-e', options.format,
'-b', options.background,
'-s', options.scale,
'-i', '-',
'-o', '-'
];
const result = spawnSync(options.mmdcPath, args, {
const result = spawnSync(options.mmdcPath, mmdcArgs, {
cwd: process.cwd(),
env: process.env,
input: content,