Skip to content

Commit 6c7fb95

Browse files
authored
Merge pull request #19 from mblawrence/master
Create figure captions
2 parents faafeb6 + 0ae450f commit 6c7fb95

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Options
3636

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

39+
- Pandoc caption and automatic image numbering - Use `{.mermaid caption="Caption Text Here"}`
3940
- Image Format - Use `{.mermaid format=svg}` Default is png
4041
- Width - Use `{.mermaid width=400}` default with is 500
4142
- Theme - Use `{.mermaid theme=forest}` default is 'default'. Corresponds to `--theme` flag of mermaid.cli
@@ -56,4 +57,4 @@ JSON and CSS configuration
5657

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

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ function mermaid(type, value, format, meta) {
1818
var attrs = value[0],
1919
content = value[1];
2020
var classes = attrs[1];
21-
var options = {width: '500', format: 'png', loc: 'inline', theme: "default"};
21+
var options = {width: '500', format: 'png', loc: 'inline', theme: "default", caption: ""};
2222
var configFile = path.join(folder, ".mermaid-config.json")
23+
2324
var confFileOpts = ""
2425
if (fs.existsSync(configFile)) {
2526
confFileOpts += " -c " + configFile
@@ -73,13 +74,17 @@ function mermaid(type, value, format, meta) {
7374
mv(savePath, newPath);
7475
}
7576

77+
var fig = "";
7678

79+
if (options.caption != "") {
80+
fig = "fig:";
81+
}
7782
return pandoc.Para(
7883
[
7984
pandoc.Image(
8085
['', [], []],
81-
[],
82-
[newPath, ""]
86+
[pandoc.Str(options.caption)],
87+
[newPath, fig]
8388
)
8489
]);
8590
}

0 commit comments

Comments
 (0)