Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to export macros correctly?

Oğuz September 3, 2021

Hi everyone. I use confluence API to fetch page content (HTML tags) using page id with a Wordpress Shortcode. Most of the elements just being viewed fine in the Wordpress page. But the elements made with macros (Table of Contents or Tabs) are not shown in the Wordpress page (I assume this is because of macros don't create elements with natural HTML). Is there any way to show Table of Contents or Tabs in my Wordpress page? or is there a way to create Table of Contents or Tabs so that confluence api fetches the content without problem?

2 answers

0 votes
Kishan Sharma
Community Champion
September 13, 2021

Hi @Oğuz Welcome to the Atlassian Community!

To start with, can you try clicking on the ellipses ... and then View Storage format of the confluence page to get the HTML tags of it and then try adding them in your Wordpress page to see if those are appearing fine ? I think since confluence uses its own stylesheet you might want to apply your custom stylesheet in your wordpress page so that the table of contents are shown correctly.

0 votes
Hana Kučerová
Community Champion
September 5, 2021

Hi @Oğuz ,

welcome to the Atlassian Community!

If I understand it correctly, what could help in your case is to add query parameter expand with value body.view to your API request.

This way you should be able to get view format of the page (= macros transformed to HTML)

See here for more info.

Oğuz September 5, 2021

Hi @Hana Kučerová ,

 

Thanks for the reply. I tried the thing you said before. But in 'view' format, the macros are fetched as blackboxes.

<p>General description about login, Log out.</p>
<div class=\"toc-macro client-side-toc-macro  conf-macro output-block\" 
data-headerelements=\"H1,H2\" data-hasbody=\"false\" data-macro-name=\"toc\" 
data-macro-id=\"36b423a4e660152a1cc5b3b1f1605726\" 
data-layout=\"default\" data-local-id=\"6d921f5b-e029-4891-8da9-75dd3c8f4cc2\"> </div>
<h2 id=\"LogIn/LogOut-LoginwithEmailandPassword\">Login with Email and Password</h2>
<p>Login with email and password</p>

I fetched this particular example with Postman (This is a part of the view format of a page)

As you can see, the table of contents macro is fetched as a <div> and its content is empty. It has only metadata in its tag. I used macro's id (data-macro-id property) to fetch its content via confluence API's GET /wiki/rest/api/content/{id}/history/{version}/macro/id/{macroId} route (Click here for the page).

And I got a response:

{

    "name": "toc",
    "body": "",
    "parameters": {

        "minLevel": {
            "value": "1"
        },
        "maxLevel": {
            "value": "2"
        }
    },
    "_links": {

        "base": "https://medianova.atlassian.net/wiki",
        "context": "/wiki"
    }
}

But still no HTML tags for the table of contents. Let's say I somehow analyzed the headers of the content and added the tags of table of contents by myself. But still, tabs feature is missing. But luckily, I managed to fetch the content of the tabs macro in storage view (using the route GET /wiki/rest/api/content/{id}/history/{version}/macro/id/{macroId})

{

    "name": "tabs-macro",
    "body": "[{\"label\":\"JSON\",\"id\":\"1\",\"content\":{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"codeBlock\",\"attrs\":{},\"content\":[{\"type\":\"text\",\"text\":\"{\\n\\\"email\\\": \\\"example@medianova.com\\\",\\n\\\"password\\\": \\\"cdfsxcdfdnv38849.\\\"\\n}\"}]},{\"type\":\"paragraph\",\"content\":[]}]}},{\"label\":\"Curl\",\"id\":\"2\",\"content\":{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"codeBlock\",\"attrs\":{},\"content\":[{\"type\":\"text\",\"text\":\"curl -X 'POST' \\\\\\n  'https://cloudproductapi-dev.medianova.com/api/login' \\\\\\n  -H 'accept: application/json' \\\\\\n  -H 'Content-Type: application/json' \\\\\\n  -H 'X-CSRF-TOKEN: ' \\\\\\n  -d '{\\n  \\\"email\\\": \\\"example@medianova.com\\\",\\n\\\"password\\\": \\\"cdfsxcdfdnv38849.\\\"\\n}'\"}]},{\"type\":\"paragraph\",\"content\":[]}]}}]",
    "parameters": {

        "alignment": {
            "value": "\"left\""
        }
    },
    "_links": {

        "base": "https://medianova.atlassian.net/wiki",
        "context": "/wiki"
    }
}

But still, no HTML tags.

Hana Kučerová
Community Champion
September 5, 2021

Hi @Oğuz ,

I've found this discussion, maybe it would help.

This endpoint is promising, but according to the discussion there are some problems.

Like Oğuz likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events