Skip to content

Commit

Permalink
Merge pull request #19 from mblawrence/master
Browse files Browse the repository at this point in the history
Create figure captions
  • Loading branch information
raghur authored Mar 15, 2018
2 parents faafeb6 + 0ae450f commit 6c7fb95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Options

You have a couple of formatting options via attributes of the fenced code block to control the rendering

- Pandoc caption and automatic image numbering - Use `{.mermaid caption="Caption Text Here"}`
- Image Format - Use `{.mermaid format=svg}` Default is png
- Width - Use `{.mermaid width=400}` default with is 500
- Theme - Use `{.mermaid theme=forest}` default is 'default'. Corresponds to `--theme` flag of mermaid.cli
Expand All @@ -56,4 +57,4 @@ 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
mermaid cli.
mermaid cli.
11 changes: 8 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function mermaid(type, value, format, meta) {
var attrs = value[0],
content = value[1];
var classes = attrs[1];
var options = {width: '500', format: 'png', loc: 'inline', theme: "default"};
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
Expand Down Expand Up @@ -73,13 +74,17 @@ function mermaid(type, value, format, meta) {
mv(savePath, newPath);
}

var fig = "";

if (options.caption != "") {
fig = "fig:";
}
return pandoc.Para(
[
pandoc.Image(
['', [], []],
[],
[newPath, ""]
[pandoc.Str(options.caption)],
[newPath, fig]
)
]);
}
Expand Down

0 comments on commit 6c7fb95

Please sign in to comment.