cancel
Showing results for 
Search instead for 
Did you mean: 

I thought that excessive blank lines had been sorted

Community Veteran
Posts: 5,338
Thanks: 1,374
Fixes: 32
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted

@jaread83 - OK one more thought, what about reverse iterating the <div> tag looking at each <p> element, if this element is 'empty' it can be removed provided it is the last element in the sub tree i.e. the next forward tag would be the </div>, just a thought.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

Thats what my second bit of code is attempting to do by using the 'reverse' order working up the DOM. You will see that for each post it is attempting to start at the end and go back looking for empty paragraph tags. Once it reaches something that doesn't match the regex it should return false and then move on to the next post.

Unfortunately my code doesn't work so it needs something else.. I am just unsure what its failing on.

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

I have added comments to demonstrate what it 'should' do...

 

    // find each instance of the post message on a page
$(".lia-message-body-content").each(function(){
// now within the post message, collect the p tags in reverse order $($("p").get().reverse()).each(function() {
// define context to the p tag var $this = $(this);
// check if the pattern matches <p>&nbsp;</p> if ($this.html().replace(/\s|&nbsp;/g, '').length == 0){
// remove if matches.. $this.remove(); console.log('found a match'); } else {
// don't do anything and stop the function if there is content return false; console.log('stop!'); }; }); });

 

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Veteran
Posts: 5,338
Thanks: 1,374
Fixes: 32
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted

@jaread83 - Well this works for me.

<html>
<head>
	<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
	<meta content="utf-8" http-equiv="encoding">
	<title>Test</title>
	<style>
		.lia-message-body-content { 
		background-color:red; 
		border:1px solid black ;
		font-size: 18px;
		}
	</style>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
	</script>
	<script>
	$(document).ready(function() {
		$(".lia-message-body-content").each(function() {
        	$($("p").get().reverse()).each(function() {
            	var $this = $(this);
            	if ($this.html().replace(/\s|&nbsp;/g, '').length == 0) {
           			$this.remove();
            	} 
            	else {
          	  		return false;
            	}
        	});
    	});
	});
	</script>
</head>
<body>
	<div class="lia-message-body-content">
		<p>Blah</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>Another Paragraph I want to keep</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
	</div>
</body>
</html>

with.pngwithout.png

So as to why is doesn't work for you then, I don't know But you might want to fix the return false statement and put it after the console.log('stop') as that is unreachable.

 

 

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

I will give this a try out on staging and see what happens. Cheers for sparing a bit of your time to help out with this.

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

That didn't work and I think its becuase of the return false. It removes the empty paragraphs from the very last instance but skips over the rest. I created a jsfiddle here:

https://jsfiddle.net/659Lejgz/

Maybe its the for each loop, maybe it needs to be an array.. hmmm

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

boom!

https://jsfiddle.net/659Lejgz/4/

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Veteran
Posts: 5,338
Thanks: 1,374
Fixes: 32
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted

Glad to see it's all working now, but are you going to install it?

Moderator's note by Adie (Dvorak) removed excessive white space.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

I can't put it up yet as there are a few other things on staging waiting to go up as well which needs to go through change management. I have implemented it on staging and it looks like it is all working. There is also an issue that if you quote someone who has empty paragraphs it carries over into the quote (very annoying!).

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

scratch that, I just extended the function to include blockquotes too and it works for that as well (woohoo).

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Veteran
Posts: 19,101
Thanks: 443
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

I shall go and play Wink

Community Veteran
Posts: 5,338
Thanks: 1,374
Fixes: 32
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted


Mook wrote:

Glad to see it's all working now, but are you going to install it?

Moderator's note by Adie (Dvorak) removed excessive white space.


Of course the space was put there for testing! Tongue

Community Veteran
Posts: 19,101
Thanks: 443
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

jaread83 wrote:
I can't put it up yet as there are a few other things on staging waiting to go up as well which needs to go through change management. I have implemented it on staging and it looks like it is all working.

Community Gaffer
Community Gaffer
Posts: 3,273
Thanks: 1,956
Fixes: 73
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted


Oldjim wrote:

@jaread83

https://community.plus.net/t5/General-Chat/H-D-T-V/m-p/1340819#M202879

Is a quote of the post with the problem

There are numerous lines with

<p>&nbsp;</p>

Just going through the threads that were mentioned in the latest update thread.

A fix for this issue will be pushed live today, you can view details of the fix on the update thread here. See the second and third item on the 'regular changes' section.

Frontend Web Developer | www.plus.net

If you have an idea to improve the community, create a new topic on our Community Feedback board to start a discussion about your idea.

Community Veteran
Posts: 19,101
Thanks: 443
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

I've thanked your post above and will just test the fix out here ..... and then edit the post after to tidy up anything that needs to be.

 

 

Well I put loads of blank lines at the end of the post which got successfully removed from the "posted" post. I've left some above to show they correctly remain.


jaread83 wrote:

Just going through the threads that were mentioned in the latest update thread.

 

 

A fix for this issue will be pushed live today, you can view details of the fix on the update thread here. See the second and third item on the 'regular changes' section.

 

 

Above, I've now quoted part of your post and put some extra blank lines within the quote which should remain, and put some at the end which should get removed Wink


And that all seems to work perfectly as expected, so another one for @Oldjim to hopefully mark your post above as a fix Smiley