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

Ben _ October 6, 2011

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

1 vote
Greg MacLellan October 25, 2012

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.

Greg MacLellan October 25, 2012

@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)/)

Ben _ October 31, 2012

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 votes
David Peterson
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.
October 7, 2011

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.

0 votes
Sherif Mansour
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 7, 2011

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events