diff --git a/index.js b/index.js index 27ddd6c..8f5d038 100644 --- a/index.js +++ b/index.js @@ -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 }); \ No newline at end of file +hexo.extend.tag.register('mermaid', mermaid(hexo.config.mermaid), { ends: true }); \ No newline at end of file diff --git a/lib/mermaid.js b/lib/mermaid.js index 436a997..6e6eecd 100644 --- a/lib/mermaid.js +++ b/lib/mermaid.js @@ -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,