A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label camelcase. Show all posts
Showing posts with label camelcase. Show all posts

Stop Confluence making CamelCase links

You can include the following code in the page, or make a macro out of it.
Note: You need to attach JQuery to one of your wiki pages, and edit the URL in the code.
{html}
<script type="text/javascript" src="/download/attachments/59835554/jquery-1.2.6.js"></script>
<script type="text/javascript"> 
//The $ notation is used by DWR. So we rely on jQuery namespace only
jQuery.noConflict();          
jQuery(document).ready(function() {
   //The camel case links have class createlink. So fetch all such links and remove the html part and retain the text part
   jQuery("a.createlink").each(function(index){
    var text = jQuery(this).text();
    if(isValidCamelCase(text)){//Only filter where we have a camelcase text and not valid yet to be created link
       jQuery(this).after(text).remove();
    }
    return true;
   });
});

function isValidCamelCase(s){
 if(s == null || s.length == 1){
  return false;
 }
 
 if(s.indexOf(' ') != -1){
  return false;
 }

 //Check for case where valid link is being created like [Test123]
 var indexOfNonUpperCaseChar = -1;
 for(var i = 0; i < s.length; i++){
  var c = s.charAt(i);
  if(!isUpperCase(c)){
   indexOfNonUpperCaseChar = i;
   break;
  }
 }
 
 if(indexOfNonUpperCaseChar == -1){
    return false;
 }
 
 var lowerCase = s.toLowerCase().substring(indexOfNonUpperCaseChar);
    var originalCase = s.substring(indexOfNonUpperCaseChar);
    if(originalCase == lowerCase){
     return false;
    }
 return true;
}

function isUpperCase(char){
 return char >= 'A' && char <= 'Z'
}
</script>
{html}

Thanks