It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using CLI to extend page links

Jakob Erber Jul 28, 2012

We want to make our glossary (wikipedia style) more robust against page title renames. Therefore we are looking for a way to extend all links such that their is always a diplay name and a link address.

For example all links of kind [linktarget] shall be extended to [linkdisplay | linktarget]

How coud this be done, using the cli interface? Or is there ab better way?

best regards

Jakob

1 answer

Probably - see How to automate adding text to Confluence pages. Be very careful with the regex you use so you match only the intended targets and get the right replacement. What is the plan for constructing the linkdisplay initially? You will need a regex that does this or else you will need to code a script to do more intricate logic.

Jakob Erber Jul 28, 2012

Thx for your quick response Bob.

Initially, we would set the display- and linkname to the same string.

What I do not yet unterstand: Does the CLI alllow to search and replace confluence markup syntax like descriped in the first question ([link alias|pagetitle#anchor])

regards

Jakob

You need to construct the appropriate regex for use in findReplaceRegex as described in the reference.

Jakob Erber Jul 29, 2012

Hello Bob,

it did so and tested it with an online regexp tester:

search

<ac:link> <ri:page ri:content-title=(.*?) /> </ac:link>

replace

<ac:link> <ri:page ri:content-title=$1 /> <ac:plain-text-link-body> <![CDATA[$1]]> </ac:plain-text-link-body> </ac:link>

but it does not work with cli. Could you tell me, how to modify the regexp to make it work with cli?

best regards

Jakob


Confluence 4.x makes it much more complicated :(. I think your regex was close. Didn't understand the ? in the title group. The bigger problem is how you specify the findReplaceRegex parameter because of all the : in the text which is a delimiter for this parameter. I modified your regex to be a bit easier to see and put it into the find replace parameter with proper quoting to handle the embedded :

--findReplaceRegex "'''(<ac:link>\\s*<ri:page ri:content-title=)\"([^\"]*)\"(\\s*/>\\s*)(</ac:link>)'':''\$1\"\$2\"\$3<ac:plain-text-link-body> <\![CDATA[\$2]]> </ac:plain-text-link-body>\$4'''"

Hard to parse with the quoting. The outer is a double quote, most others are single quotes. It is easiest to understand as 'a':'b' and then this is quoted again with inner quotes needing to be doubled: '''a'':''b'''. Then the the string needs to be double quoted since it contains blanks and all cli parameters that contain blanks must be double quoted. Inner double quotes must be escaped.

In my case (OSX), the $ for the group variables needed to be escaped for the command processor (not needed for Windows clients).

A more surprising discovery that may upset your plans on 4.x is that the editor will replace your newly extended link back to the simplified link if the page is ever edited :(.

Jakob Erber Jul 30, 2012

Thx a lot Bob for helping with this regexp.

Yes, your last sentence upsets our plans. Seems like confluence tries to optimize away link bodies, which are identical to link titels. Not an intelligent bevaiour in my opinion.

regards

jakob

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

5,799 views 22 30
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you