Skip to content

Commit

Permalink
feat(config): allow pass through of puppeteer configuration
Browse files Browse the repository at this point in the history
See #21
  • Loading branch information
raghur committed May 4, 2018
1 parent 6c7fb95 commit cb9764f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@ JSON and CSS configuration
---------------------------

Mermaid cli allows you to specify additional options in a json configuration file and a css file. `mermaid-filter`
will look in the current directory for `.mermaid-config.json` and `.mermaid.css` and if found, pass them in to
will look in the current working directory for `.mermaid-config.json` and `.mermaid.css` and if found, pass them in to
mermaid cli.

Puppeteer Configuration - `mermaid-filter` will look in the current working directory for a `.puppeteer.json` and pass it
on to mermaid cli (`-p` option of mmdc)if found
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ function mermaid(type, value, format, meta) {
var classes = attrs[1];
var options = {width: '500', format: 'png', loc: 'inline', theme: "default", caption: ""};
var configFile = path.join(folder, ".mermaid-config.json")

var confFileOpts = ""
if (fs.existsSync(configFile)) {
confFileOpts += " -c " + configFile
}
var puppeteerConfig = path.join(folder, ".puppeteer.json")
var puppeteerOpts = ""
if (fs.existsSync(puppeteerConfig)) {
puppeteerOpts += " -p " + puppeteerConfig
}
var cssFile = path.join(folder, ".mermaid.css")
if (fs.existsSync(cssFile)) {
confFileOpts += " -C " + cssFile
Expand All @@ -49,7 +53,7 @@ function mermaid(type, value, format, meta) {
// console.log(outdir);
var savePath = tmpfileObj.name + "." + options.format
var newPath = path.join(outdir, `${prefix}-${counter}.${options.format}`);
var fullCmd = `${cmd} ${confFileOpts} -w ${options.width} -i ${tmpfileObj.name} -t ${options.theme} -o ${savePath}`
var fullCmd = `${cmd} ${confFileOpts} ${puppeteerOpts} -w ${options.width} -i ${tmpfileObj.name} -t ${options.theme} -o ${savePath}`
// console.log(fullCmd, savePath)
exec(fullCmd);
//console.log(oldPath, newPath);
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mermaid-filter",
"version": "1.1.0",
"version": "1.2.0",
"description": "Pandoc filter for mermaid",
"main": "index.js",
"scripts": {
Expand All @@ -20,8 +20,8 @@
"dependencies": {
"imgur": "^0.2.0",
"lodash": "~3.10.1",
"mermaid": "^7.1.0",
"mermaid.cli": "^0.3.1",
"mermaid": "^7.1.2",
"mermaid.cli": "^0.4.6",
"pandoc-filter": "^0.1.3",
"tmp": "0.0.28"
}
Expand Down

0 comments on commit cb9764f

Please sign in to comment.