The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 

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

Steve Goldberg
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 Champions.
February 20, 2013

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?

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Steve Goldberg
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 Champions.
February 20, 2013

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).

Anindita
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 10, 2019

Where exactly do I need to put this code? I am already using a set of code for PDF export. so, Please suggest.

Thanks!

Ryan Leonard
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 25, 2020

Hi Anindita,

This solution leverages the "At end of the body" feature that places custom HTML/Javascript code at the end of every Confluence page.

  • Go to Confluence Administration
  • Select Custom HTML on the left panel, under the Look and Feel section
  • On the "At end of the body" box, insert the code

Like • Saranya Murthy likes this
4 votes
Kipland Iles
Contributor
July 19, 2017

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.

Volodymyr Volkov
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 17, 2018

Thank you so much, man!

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

Jonathan Sabah
August 1, 2019

This is such a tedious process... I wish Atlassian did not introduce them in the first place.

Like • Renata Mann likes this
Kipland Iles
Contributor
August 1, 2019

I had hoped that it would no longer be an issue with the new editing experience but seems to still be there. I do most of my docs in Google Docs now anyway but still need to use Confluence for the JSD KB Articles. Maybe it gets fixed on the next UX release.

Agreed - it is tedious and should be unnecessary. 

Like • Saranya Murthy likes this
Saranya Murthy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 2, 2021

Thanks very much, @Kipland Iles . Like Volodymyr, I had also been struggling with this for a long time and am pleased to have your solution.

0 votes
Keith Bloomfield
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 13, 2021

Instead of pressing Enter for a new line, press Shift + Enter.

I know this doesn't solve the bulk case already sorted for those w/admin rights, but I was led here after Googling the "edit a page" case where annoying whitespace appears in undesired places. 

0 votes
Jameel Harris
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 19, 2018
<script>
AJS.toInit(function() {
   AJS.$("document").ready(function() {
     AJS.$("br").remove();
   });
 });
</script>

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

TAGS
AUG Leaders

Atlassian Community Events