Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Adding Internal Links Using REST API

Edited

Hello,

I am updating the content of the page by giving the update function the whole html code. Everything is working perfectly, except for <a> tags that need to be linked to existing pages in confluence. I updated the href attribute to meet the url of the internal page to be linked to like

'/wiki/spaces/spacekey/pages/pageid'

and added  the attributes that I found I should be adding to link this <a> tag to the page properly, which are 

data-linked-resource-id

data-linked-resource-version

data-linked-resource-type

So, the <a> tag I am inserting looks like this:

<a href="/wiki/spaces/spacekey/pages/pageid" data-linked-resource-id="targetpageid" data-linked-resource-version="targetpageversion" data-linked-resource-type="page">Page Name</a>

However, after the update is done successfully, I check the updated page html to find out that only href is updated successfully, while all the other attributes are ignored, and a new rel attribute is added. It looks like this:

<a href="/wiki/spaces/spacekey/pages/pageid" rel="nofollow">Page Name</a>

Is there a way to force adding these attributes that are being ignored? Or is there another proper way to insert <a> tags linking to internal pages in confluence?

Thank you.

1 answer

0 votes
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 31, 2021

Hi @Hani Suliman 

Use the below link for reference to add the reference in the same page using anchor tags

https://community.atlassian.com/t5/Confluence-questions/How-to-link-to-headings-on-the-same-page-new-editor/qaq-p/1250592

Thanks,
Pramodh

Hi @Pramodh M

I thought I had a solution for this but my solution does not work with pages created for the V2 Editor.   The following is my code:

def content_url(link, description=None, page=None):
"""Encode a Link to an anchor in this page or another page

Args:
----
link: Name of anchor to link to
description: alternative description to use, (or use link if ommited)
page: page where anchor can be found (blank = current page)

"""
if description is None:
description = link
output = '<ac:link ac:anchor="{0}">'.format(link)
if page:
output += '<ri:page ri:content-title="{0}"/>'.format(page)
output += '<ac:plain-text-link-body><![CDATA[' + description + ']]>'
output += '</ac:plain-text-link-body></ac:link>'
return output

Again it works in V1 editor created pages but not in V2 editor created pages.  Can you tell me in concrete terms what to change in the syntax of the storage format required to encode the anchor since ac:anchor="<name>" no longer works. Better still if there is a complete and unambiguous document explaining the storage format then please share it with us.  Trial and error is a fickle master.

Suggest an answer

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

Atlassian Community Events