[CONFLUENCE] How can I remove empty whitespace / paragraph tags?

One common problem with Confluence is that it frequently generates phanatom white space above and below elements such as macros, tables, images, etc. Removing them can be an impossible task. How can you do it?

3 answers

1 accepted

This widget could not be displayed.

The answer to this is to use jQuery. Place the following JavaScript in the "At end of the BODY" section of your Custom HTML (this is not possible AFAIK with Confluence OnDemand).

<script type="text/javascript">
jQuery('p').each(function() {
    var $this = $(this);
    if($this.html().replace(/\s| /g, '').length == 0)
        $this.remove();
});
</script>

Full credit for this script goes to "ruslyrossi" on StackOverflow (http://stackoverflow.com/questions/10225967/remove-p-nbsp-p-with-jquery-if-no-value).

This widget could not be displayed.

For Confluence Cloud I found that if you position your cursor immediately to the left of a macro while editing, a single vertical line will appear. If you hit the backspace (delete) key then that space will go away briefly and then reappear. If you do that for all macros on the page then the <p><br></p> will no longer be inline between the macros after saving/publishing.

Thank you so much, man!

You can't imagine how long I was fighting with that extra space until I noticed your comment.

This widget could not be displayed.
<script>
AJS.toInit(function() {
   AJS.$("document").ready(function() {
     AJS.$("br").remove();
   });
 });
</script>

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

400 views 4 6
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