Is there a way to have Confluence generate links to external websites automatically on an identifier other than @ or camelCase?

We have items with unique part numbers with all part numbers ending always in '-ND' (ex. 129-555-ND). Is there a way to have this automatically link without going through the addition of [129-555-ND@identifier] ? Preferably I'd just like anything that follows the format of 'anything-ND' (spaces are the only delimiter) to retain the text and become an external hyperlink that goes to our search engine. I supposed the camelCase auto link would be another example of this type of functionality, but obviously not quite what I want.

Is anyone aware of a plugin or resource for developing/modifying such a functionality?

3 answers

I did this with a total hack -- would love to see this as a plugin though. I just search for a regex and replace it with my custom HTML (which happens to be a link).

I used it to auto-link JIRA ticket numbers, and also to auto-link tickets to our external customer support site (by writing either "ticket 23445" or "#23445").

I used the ba-replacetext javascript by Ben Alman, and then created a javascript file:

jQuery.getScript('https://site.com/common/jquery.ba-replacetext.js', function() {
    console.log('Doing text replacements..');
    jQuery('article *')
        .replaceText( /([A-Za-z]{2,3}-\d{1,5})/gi, '<a href="https://jira.site.com/jira/browse/$1" title="View JIRA issue $1 (new tab)" target="_blank">$1</a>' )
        .replaceText( /(#|ticket ?)(\d{5,7})/gi, '<a href="https://support.site.com/ticket/$2" title="View support ticket #$2 (new tab)" target="_blank">$1$2</a>' )
}

I then modified confluence's `/opt/atlassian/confluence/confluence/decorators/includes/header.vm` to include my file, by adding at the bottom:

<script type="text/javascript" src="https://site.com/common/confluence-include.js" ></script>

After restarting confluence, this works great.

Of course, the JIRA inbound links don't work but while migrating to confluence, I have a lot of content that already has JIRA issue numbers embedded in the text (that auto-link from our old wiki) and so this at least gives me usable links.

I'm new to confluence, but have been using this same method in JIRA for over a year to auto-link support tickets, changesets, build references, etc. The only thing to watch out for is after upgrades, you have to reapply the header change.

@bombledmonk : In your case, the replace line would be something like: .replaceText( /(\S+-ND)/gi, '<a href="https://site.com/products/$1" title="View product $1 info (new tab)" target="_blank">$1</a>') though I'd recommend being more precise to only link plausible part numbers and avoid false positives (eg, if all numbers were like the pattern you gave 525-446-ND, you could use /(\d{3}-\d{3}-ND)/)

That looks like it would accomplish my goal as stated. Thanks for the great idea. I've tested out something similar now and it more or less does what I want. The only problem I've discovered now is that SEO value is likely lost when the links are rendered using javasript after the page load.

0 vote

I don't think there is any way to do this. The only option you have is using the Confluence Short Cut links feature: http://confluence.atlassian.com/display/DOC/Configuring+Shortcut+Links which requires the @ symbol.

I'm not aware of any existing plugins that do this, but you could build something that watches for page create/edit events, then parses the entered text looking for patterns that match your requirements, and then replaces them with the full URL, or possibly the '@' markup if you're ok with it being present. But seems like a custom plugin to me.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

899 views 23 12
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you