4

I am parsing dita xml and I have to generate Confluence Storage Format.

I am facing difficulty with Anchor macro, while dita format have xref who behave the same way as html local link <xref href="#id">title</xref>....<any id="id"..., confluence seam to have its own unique synthax.

Did someone have any good example on how to build a correct anchor and link it properly?

Saloparenator
  • 330
  • 1
  • 13

4 Answers4

3

I finally figured it out.

Instead of id on an element, we insert an anchor were the link should send the user, I inserted it just above the header. <ac:structured-macro ac:name="anchor"><ac:parameter ac:name="">The_Id</ac:parameter></ac:structured-macro>

And anchor link are built like these. <ac:link ac:anchor="The_Id"><ac:plain-text-link-body><[CDATA[text describing the link]]></ac:plain-text></ac:link>

Tested on Confluence 5.7

Saloparenator
  • 330
  • 1
  • 13
2

The anchor macro actually creates a HTML <span> element which has an ID that contains the title of the page and the anchor.

<span id="CONFLUENCEPAGENAME-ANCHORNAME" class="confluence-anchor-link"></span>

So, if your confluence page represents a topic, that should be quite easy to implement (Because CONFLUENCEPAGENAME equals your topic title or key or ID or whatever you use). Just Create an empty confluence page, add an anchor macro, save it and examine the rendered HTML.

Stefan Jung
  • 1,209
  • 11
  • 20
  • Maybe I have miss formulated my question, I dont need to know what confluence generate for the browser but what I generate for it's Rest Api. – Saloparenator Feb 12 '16 at 14:46
2

There is a small mistake in the Saloparenator's answer. The anchor link is:

<ac:link ac:anchor="The_Id">
    <ac:plain-text-link-body>
        <[CDATA[text describing the link]]>
    </ac:plain-text-link-body>
</ac:link>
0

If the page you want to link to has a TableOfContents - and you want to link to a section in this page1 from a different page2...

View page 1, and click on the link in the TableOfContents, which will take you to the section on the same page1.

Now copy this URL from your browser address bar (it will be something like http://confluence/page1#anchor), and go to your page2 where you want to put the link.

Edit the page2, and paste the link pointing to page1.

Sagan
  • 2,033
  • 2
  • 14
  • 12