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

Replace text which is displayed to users with a link

Matt
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2020

What I am looking to accomplish is to search a page's body for a specific string using RegEx and then replace that text with an HTML link to be rendered by Confluence Cloud. I am currently doing this is in Server with custom JavaScript in the "custom header/footer" section of the admin interface but I am now faced with finding an equivalent solution for the cloud.

My imagination thinks I may be able to use the PageView event in ScriptRunner to manipulate the page body and return a new body to be rendered. I haven't seen any examples of this, is it possible?

1 answer

1 accepted

0 votes
Answer accepted
Helmy Ibrahim _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2021

Hi Matt,

I guess listening to the 'Page Viewed' event would be too much. I would suggest listening to the 'Page Updated' and 'Page Created' events. 

Here's an example PUT request to update a page body in the Confluence cloud.

// Page ID
def id = "20873217"

def content = get("/wiki/rest/api/content/${id}").asObject(Map).body

put("/wiki/rest/api/content/${content.id}")
    .header('Content-Type', 'application/json')
    .body([
        version: [
            number: content.version.number + 1
        ],
        title: content.title,
        type: content.type,
        body: [
            storage: [
                value: 'New Content here',
                representation: 'storage'
            ]
        ]
    ])
    .asObject(Map)

Cheers,
Helmy

Suggest an answer

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

Atlassian Community Events