Skip to content

Commit

Permalink
feat: support mermaid graphs (kovetskiy#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
carnei-ro authored Oct 25, 2021
1 parent ee0a6e2 commit e635d1f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/mark/stdlib/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ func templates(api *confluence.API) (*template.Template, error) {
`{{ if .Title }}<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}{{ end }}`,
`<ac:rich-text-body>{{printf "\n"}}{{ end }}`,

`<ac:structured-macro ac:name="code">{{printf "\n"}}`,
/**/ `<ac:parameter ac:name="language">{{ .Language }}</ac:parameter>{{printf "\n"}}`,
`<ac:structured-macro ac:name="{{ if eq .Language "mermaid" }}cloudscript-confluence-mermaid{{ else }}code{{ end }}">{{printf "\n"}}`,
/**/ `{{ if eq .Language "mermaid" }}<ac:parameter ac:name="showSource">true</ac:parameter>{{printf "\n"}}{{ else }}`,
/**/ `<ac:parameter ac:name="language">{{ .Language }}</ac:parameter>{{printf "\n"}}{{ end }}`,
/**/ `<ac:parameter ac:name="collapse">{{ .Collapse }}</ac:parameter>{{printf "\n"}}`,
/**/ `{{ if .Title }}<ac:parameter ac:name="title">{{ .Title }}</ac:parameter>{{printf "\n"}}{{ end }}`,
/**/ `<ac:plain-text-body><![CDATA[{{ .Text | cdata }}]]></ac:plain-text-body>{{printf "\n"}}`,
Expand Down
34 changes: 34 additions & 0 deletions pkg/mark/testdata/codes.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,37 @@
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:name="cloudscript-confluence-mermaid">
<ac:parameter ac:name="showSource">true</ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:plain-text-body><![CDATA[graph TD;
A-->B;
A-->C;
B-->D;
C-->D;]]></ac:plain-text-body>
</ac:structured-macro>
<ac:structured-macro ac:name="expand">
<ac:parameter ac:name="title">my mermaid graph</ac:parameter>
<ac:rich-text-body>
<ac:structured-macro ac:name="cloudscript-confluence-mermaid">
<ac:parameter ac:name="showSource">true</ac:parameter>
<ac:parameter ac:name="collapse">true</ac:parameter>
<ac:parameter ac:name="title">my mermaid graph</ac:parameter>
<ac:plain-text-body><![CDATA[graph TD;
A-->B;
A-->C;
B-->D;
C-->D;]]></ac:plain-text-body>
</ac:structured-macro>
</ac:rich-text-body>
</ac:structured-macro>
<ac:structured-macro ac:name="cloudscript-confluence-mermaid">
<ac:parameter ac:name="showSource">true</ac:parameter>
<ac:parameter ac:name="collapse">false</ac:parameter>
<ac:parameter ac:name="title">my mermaid graph</ac:parameter>
<ac:plain-text-body><![CDATA[graph TD;
A-->B;
A-->C;
B-->D;
C-->D;]]></ac:plain-text-body>
</ac:structured-macro>
24 changes: 24 additions & 0 deletions pkg/mark/testdata/codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ collapse-and-title
```c collapse
collapse-no-title
```

```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```

```mermaid collapse title my mermaid graph
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```

```mermaid title my mermaid graph
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```

0 comments on commit e635d1f

Please sign in to comment.