Git Product home page Git Product logo

Comments (6)

elliotlayden avatar elliotlayden commented on May 24, 2024 2

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?

from conflr.

yutannihilation avatar yutannihilation commented on May 24, 2024

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. #54 (comment)

from conflr.

andrewcstewart avatar andrewcstewart commented on May 24, 2024

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 tags for a macro within Confluence itself and then just copy+paste that into one's Rmd.

from conflr.

yutannihilation avatar yutannihilation commented on May 24, 2024

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.

from conflr.

andrewcstewart avatar andrewcstewart commented on May 24, 2024

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 :)

from conflr.

yutannihilation avatar yutannihilation commented on May 24, 2024

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:

Thanks, not sure how useful it would be, but I added a function confl_contentbody_convert() (#58).

from conflr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.