How can I get rendered macros instead of storage format?

873 views
Skip to first unread message

Yong Chong, Long

unread,
Sep 17, 2014, 1:41:02 AM9/17/14
to atlassian-...@googlegroups.com, Kai Fung Chong, HengHwa Loi
I'm developing a plugin that accept user content inside the macro body, these content include other macros as well as rich text content.

The problem is, I couldn't render the embeded macro in XHTML format, what I see when I view the page is storage format, here's the screenshot when I edit the page and the result.

Edit page:





View page:


Daniel Wester

unread,
Sep 17, 2014, 11:18:52 AM9/17/14
to atlassian-...@googlegroups.com, kaifun...@servicerocket.com, hengh...@servicerocket.com

Matthew Jensen

unread,
Sep 17, 2014, 8:30:48 PM9/17/14
to atlassian-...@googlegroups.com, kaifun...@servicerocket.com, hengh...@servicerocket.com
You shouldn't need to do the conversion yourself, when you call back in to Confluence to collect the macro body, you should get the rendered HTML.

How are you collecting the macro body?

--
You received this message because you are subscribed to the Google Groups "Atlassian Connect Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to atlassian-connec...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yong Chong, Long

unread,
Sep 17, 2014, 11:51:47 PM9/17/14
to atlassian-...@googlegroups.com, kaifun...@servicerocket.com, hengh...@servicerocket.com
@Daniel

Thanks for the link, that could tbe the answer because I'm using REST API to retrive the macro body, perhaps there's another step need to be done in order to display the content as XHTML format.

@Matthew

I'm using REST API to retrive the macro body, here's the snippet that does that:

module.exports = function(app, addon) {
  app.get('/demo', addon.authenticate(), function (req, res) {

    var macroHash = req.query.macroHash;
    var pageId = req.query.pageId;
    var pageVersion = req.query.pageVersion;
    var macroBodyUri = '/rest/api/content/' + pageId + '/history/' + pageVersion + '/macro/hash/' + macroHash;

    addon.httpClient(req).get({
      uri: macroBodyUri
    }, function(err, response, body) {
      if (err) {
        console.log(error);
      } else {
        macro = JSON.parse(body);
        res.render('template', {
          body: macro.body,
        });
      }
    });
  });
}

Also FYI, currently I'm using `staticContentMacros` to render the macro, haven't explore `dynamicContentMacros` yet, could this be the reason that the content is not able to render in XHTML format?

Peter Brownlow

unread,
Sep 18, 2014, 2:14:24 PM9/18/14
to atlassian-...@googlegroups.com, kaifun...@servicerocket.com, hengh...@servicerocket.com
Hi,

If you use a static content macro then Confluence will treat your add-on's response as storage format XHTML, sanitise it and display it directly in the page. If you're using a dynamic content macro then your response lives inside an iframe (i.e. not directly in the page) and when you're returning iframe content you can return HTML.

It looks like you are returning HTML, which Confluence then sanitises, which is why the tags are displayed. As Matthew said, "when you call back in to Confluence to collect the macro body, you should get the rendered HTML". I think that if you switch to a dynamic content macro then it will work a lot better.

Alternatively, you could somehow return storage format XHTML and stay with a static content macro, but I think that this would probably be harder.


-Peter
Reply all
Reply to author
Forward
0 new messages