Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ac:image macro #245

Closed
Fethbita opened this issue Jan 25, 2023 · 4 comments
Closed

ac:image macro #245

Fethbita opened this issue Jan 25, 2023 · 4 comments

Comments

@Fethbita
Copy link
Contributor

Fethbita commented Jan 25, 2023

Hi, Sylvain Malnuit previously created an ac:image macro on their branch (Related issue). I added a width option to use it myself. I would like it if it would be merged. Here is the diff:

diff --git a/pkg/mark/stdlib/stdlib.go b/pkg/mark/stdlib/stdlib.go
index f1bc132..0cd1c06 100644
--- a/pkg/mark/stdlib/stdlib.go
+++ b/pkg/mark/stdlib/stdlib.go
@@ -84,6 +84,14 @@ func templates(api *confluence.API) (*template.Template, error) {
 					"]]><![CDATA[]]]]><![CDATA[>",
 				)
 			},
+
+			"convertAttachment": func(data string) string {
+				return strings.ReplaceAll(
+					data,
+					"/",
+					"_",
+				)
+			},
 		},
 	)
 
@@ -192,6 +200,10 @@ func templates(api *confluence.API) (*template.Template, error) {
 			`<ac:emoticon ac:name="{{ .Name }}"/>`,
 		),
 
+		`ac:image`: text(
+			`<ac:image {{ if .Width}}ac:width="{{ .Width }}"{{end}}><ri:attachment ri:filename="{{ .Attachment | convertAttachment }}"/></ac:image>`,
+		),
+
 		/* https://confluence.atlassian.com/doc/widget-connector-macro-171180449.html#WidgetConnectorMacro-YouTube */
 
 		`ac:youtube`: text(

Create a macro like the following

<!-- Macro: \!\[.*\]\((.+)\)\<\!\-\- (.*) \-\-\>
     Template: ac:image
     Attachment: ${1}
     Width: ${2} --> 

just attach any image with the following

![Example](../images/example.png)<!-- 300 -->

The width will be the commented html after the image.

@joyfulrabbit
Copy link
Contributor

The width is super nice, github markdown has a automatic image resizing that confluence does not....

@mrueg
Copy link
Collaborator

mrueg commented Feb 3, 2023

@Fethbita if @malys or you can open a PR for this, we can take a look and get it in :)

@Fethbita Fethbita mentioned this issue Feb 4, 2023
@Fethbita
Copy link
Contributor Author

Fethbita commented Feb 4, 2023

@mrueg PR created (#250).

@Fethbita
Copy link
Contributor Author

PR #250 merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants