fix bugs
This commit is contained in:
parent
1e5bdba412
commit
f73ca03ca2
@ -1,11 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const tmp = require('tmp');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
function mermaid(config) {
|
||||
return function(args, content) {
|
||||
let options = Object.assign({}, config);
|
||||
let caption = '';
|
||||
let caption = '', configPath = '';
|
||||
args.forEach(arg => {
|
||||
const arr = arg.split(':');
|
||||
if (arr.length == 1) {
|
||||
@ -16,7 +18,7 @@ function mermaid(config) {
|
||||
}
|
||||
});
|
||||
|
||||
const mmdcArgs = [
|
||||
let mmdcArgs = [
|
||||
'-t', options.theme,
|
||||
'-w', options.width,
|
||||
'-H', options.height,
|
||||
@ -27,6 +29,19 @@ function mermaid(config) {
|
||||
'-o', '-'
|
||||
];
|
||||
|
||||
const arr = content.split('<!-- endconfig -->');
|
||||
if (arr.length == 2) {
|
||||
const mmdConfig = arr[0];
|
||||
content = arr[1];
|
||||
|
||||
const tmpFile = tmp.fileSync();
|
||||
configPath = tmpFile.name;
|
||||
fs.writeFileSync(configPath, mmdConfig);
|
||||
}
|
||||
if (configPath !== '') {
|
||||
mmdcArgs.push('-c', configPath);
|
||||
}
|
||||
|
||||
const result = spawnSync(options.mmdcPath, mmdcArgs, {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
|
Loading…
x
Reference in New Issue
Block a user