Using Confluence macros in the Rmd?
Is it already somehow possible to directly invoke Confluence's macros (https://confluence.atlassian.com/doc/macros-139387.html) from within the source Rmd?
Thanks for the idea. Do you mean using macro in markup form like this?
{expand:This is my message}
This text is _hidden_ until you expand it.
{expand}
If so, it would be a bit tricky because Confluence's REST API doesn't directly support the format.
c.f. https://github.com/line/conflr/issues/54#issuecomment-567373877
Well, I guess I just mean being able to invoke macros in any way possible. I'm not that familiar with the Confluence API, but it looks like you send the body as html (is this "storage format"?)?
Funny enough, I just tried inserting the following macro into my Rmd and it rendered properly when published to Confluence:
<p><ac:structured-macro ac:name="status" ac:schema-version="1" ac:macro-id="77d8c727-052a-4875-9591-9d0674e2fa22"><ac:parameter ac:name="title">Status</ac:parameter></ac:structured-macro></p>
Pretty neat! So it looks like a decent solution is to figure out the
Oh, I see. Glad to know inserting the <ac:...> tag directly works! (though probably I need to implement some tweak to prevent the content of the tag from various conversions by conflr...)
but it looks like you send the body as html (is this "storage format"?)?
Yes, it's Confluence Storage Format.
Gotcha. Looks like it's some kind of custom XML/HTML format. I think I have a better idea of how the render + API posting process is working in this package now.
One idea is that one can use the htmltools package inside of a knitr chunk, like so:
```{r}
library(htmltools)
p(tag("ac:structured-macro",list("ac:name"="status", "ac:schema"="1", tag("ac:parameter", list("ac:name"="title", "DRAFT")))))
```
It would probably be rather tedious to encode every Confluence macro in its own function, but it might be fairly easy to just create some tag() functions for the most relevant tags (ac:structured-macro and ac:parameter).
I actually think it might be possible to do something like you originally suggested with the markup format too, by having a function that calls the conversion endpoint on Confluence's API:
Their documentation provides the following example of posting some markup:
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d'{"value":"{cheese}",
"representation":"wiki"}' "http://localhost:8080/confluence/rest/api/contentbody/convert/storage"
| python -mjson.tool
...which gets converted to storage format:
{
"_links": {
"base": "http://localhost:8080/confluence"
},
"representation": "storage",
"value": "<ac:structured-macro ac:name=\"cheese\" />"
}
So one idea could be to have a function convert_macro that talks to the Confluence API to convert the macro markup and returns the corresponding storage format:
conflr::convert_macro(
"{expand:This is my message}
This text is _hidden_ until you expand it.
{expand}"
)
That function could just be used on its own easily enough, but it could also possibly be used somewhere in the rendering process via hook or similar. For example, with a knitr chunk hook, I think one could then define a custom knitr block, like so...
```{block, type='conflr-macro'}
{expand:This is my message}
This text is _hidden_ until you expand it.
{expand}
```
Defining a knitr engine may be another approach, but I think that has the disadvantage of not being able to share variables within the block w/o getting fancy with engine options. (The same may be true of the block chunk engine though).
Anyway, none of this might be useful or necessary, but I thought I'd make a record of some options :)
So one idea could be to have a function
convert_macrothat talks to the Confluence API to convert the macro markup and returns the corresponding storage format:
Thanks, not sure how useful it would be, but I added a function confl_contentbody_convert() (https://github.com/line/conflr/pull/58).
Could you provide an example of how this new function would be used within an Rmd document? I've had some success embedding macro's like this:
p(tag("ac:structured-macro", list("ac:name"="expand", "ac:schema"="1", "ac:macro-id"="80df63ef-6ccf-4270-84d9-d3bc5f9a3ff8", tag("ac:parameter", list("ac:name"="title", "Click here to expand...")), tag("ac:rich-text-body", "Hidden Text"))))
But what I would like to do is embed images within the Expand macro (and/or nest more Expand's). Do you know if this is possible?