Home/Confluence storage format reference
Confluence storage format
Anchor links in Confluence storage format
An anchor link is an ac:link with an ac:anchor attribute, with or without a ri:page. On the same page it renders as an a href starting with a hash. The ADF form is an ordinary link mark with an href of the hash plus the anchor name.
Storage format
<ac:link ac:anchor="anchor">
<ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body>
</ac:link>
<ac:link ac:anchor="anchor"><ri:page ri:content-title="pagetitle" /><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link>
In the editor
| How | Note |
|---|---|
| Insert the anchor macro from the toolbar or by typing a slash and the macro name, then link to it. | Per the Atlassian documentation. |
As ADF (Confluence Cloud)
The ADF that Confluence Cloud builds for:
<p><ac:link ac:anchor="anchor"><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>
{
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"text": "Anchor Link",
"type": "text",
"marks": [
{
"type": "link",
"attrs": {
"href": "#anchor"
}
}
]
}
]
}
],
"version": 1
}
Examples
Storage format sent
<p><ac:link ac:anchor="anchor"><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>A link to an anchor on the same page, the first anchor example in the documentation.
Rendered view (HTML)
<p><a href="#anchor">Anchor Link</a></p>Storage format after the round trip through ADF
<p><ac:link ac:anchor="anchor"><ac:link-body>Anchor Link</ac:link-body></ac:link></p>Sent to Confluence Cloud on .
Storage format sent
<p><ac:link ac:anchor="anchor"><ri:page ri:content-title="pagetitle"/><ac:plain-text-link-body><![CDATA[Anchor Link]]></ac:plain-text-link-body></ac:link></p>A link to an anchor on another page, where the target page does not exist.
Rendered view (HTML)
<p><a class="createlink" href="/wiki/pages/createpage.action?spaceKey=SD&title=pagetitle&linkCreation=true&fromPageId=<page id>">Anchor Link</a></p>Storage format after the round trip through ADF
<p><ac:link><ri:page ri:content-title="pagetitle" /><ac:link-body>Anchor Link</ac:link-body></ac:link></p>Sent to Confluence Cloud on .
Storage format sent
<p><a href="#section-two">same-page hash link</a></p>A plain a href with only a hash, written without any ac: element.
Rendered view (HTML)
<p><a href="#section-two" rel="nofollow">same-page hash link</a></p>Storage format after the round trip through ADF
<p><ac:link ac:anchor="section-two"><ac:link-body>same-page hash link</ac:link-body></ac:link></p>Sent to Confluence Cloud on .
What changes in conversion
- A same-page anchor link becomes an ADF link mark with the href set to the hash and the anchor name. Storage comes back as an ac:link with ac:anchor and an ac:link-body.
- The body changes from a plain-text-link-body CDATA to a link-body. The text is the same, but the CDATA wrapper is gone.
- A plain a href with only a hash is converted into an ac:link with ac:anchor, so a hand-written hash link returns in the ac:link form.
- For an anchor link on another page, the ac:anchor attribute is not kept. The result links to the page and the anchor is gone.
- The anchor link with an image body could not be saved back as ADF in this test, since the save was refused with a conflict error.
Pitfalls
- An anchor link to a page that is not found is displayed as a create page link, so the anchor part is never reached.
- The view keeps the anchor name as written. A name with a space produced an href of a hash followed by the name with the space, which is not a clean address.
- The anchor macro is invisible to the reader, so nothing on the page shows whether the name a link uses exists.
Related
- anchor macro
- <ac:link> to a page
- Link bodies: plain text and rich
- <a href> external links
- <h1> to <h6> headings