cancel
Showing results for 
Search instead for 
Did you mean: 

I thought that excessive blank lines had been sorted

Community Veteran
Posts: 38,246
Thanks: 936
Fixes: 56
Registered: 15-06-2007

I thought that excessive blank lines had been sorted

@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>
39 REPLIES
Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

I had a script that would remove all of these random blank paragraphs when rendering each post and they would still be visible when editting the post (I can't intercept them betweem posting and saving it in the system) but there was too much outcry over users having control over their own posts so I removed the script entirely. I guess some users feel the need to hit return twice when composing replies or leaving empty paragraphs at the end of their messages. That is fine by me and its down to the users how they wish to compose their messages.

We were looking at removing the empty paragraphs at the end of each post but this was not possible to do so.

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: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

I'm not sure how the quoted user added all those blank lines. Resting on the return key? Wink Just kidding. They could always edit their message if after posting it was not formatted correctly.

Or I could put my script back in that removed all blank lines on the rendered message but this would still be displayed on the emails that get generated..

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: 38,246
Thanks: 936
Fixes: 56
Registered: 15-06-2007

Re: I thought that excessive blank lines had been sorted

I have reported it to the mods for sorting

Community Veteran
Posts: 19,099
Thanks: 434
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

Don't you dare put your script back Tongue Anyway, I thought Lithium were going to sort out the removal of blank lines at the end of a post (no where else).

Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

No, that would be down me putting a script in to do that.

I found it almost impossible to do consistently and its on my list of enhancements to look at in the future. It's much easier to go through an entire page of posts and remove dead paragraphs than it is to selectively select each post and systematically read the content, work out where the content ends and remove everything after that.

It's on my list and I may need to get someone with advanced knowledge of jQuery to help me out on that when i get round to it (and I'm pretty good with jQuery!).

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,099
Thanks: 434
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

Nothing as simple as EOF and remove CR's before it then Grin

Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

thats going back to the days of visual basic with EOF (end of file) lol. If only things were that simple.

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,099
Thanks: 434
Fixes: 21
Registered: 31-08-2007

Re: I thought that excessive blank lines had been sorted

Or even further back, just plain old DOS.

Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

This is already on my enhancement list so I will be looking into it in the future at some point. Just need to come up with a way to remove the space after the content rather than inbetween.

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: 4,759
Thanks: 1,049
Fixes: 27
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted

@jaread83 - I know it's not really recommended for HTML but I don't think the document structure will be changing to often so I would be inclined to use a regular expression to do this.

You said you'll be using jQuery so maybe something like this in a replace() :

 

$string = replace('/<p[^>]*><\\/p[^>]*>/i', '', $string)

This if from the top of the head so may not even work.

 

Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

That would remove all of the empty paragraphs which was universally hated by the test users. What you have provided isn't too far off what I already wrote originally:

    $('p').each(function() {
       var $this = $(this);
       if ($this.html().replace(/\s|&nbsp;/g, '').length == 0)
           $this.remove();
    });

I had been trying to do it in a reverse order and jump from post to post to remove the end tags and this is what I got before giving up becuase it didn't work:

    $(".lia-message-body-content").each(function(){
        // $($("p").reverse()).each(function() {
        $($("p").get().reverse()).each(function() {
            var $this = $(this);
            if ($this.html().replace(/\s|&nbsp;/g, '').length == 0){
            $this.remove();
            console.log('found a match');
            } else {
                 return false;
                 console.log('stop!');
            };
        });
    });

So it's something I have certainly been trying to crack with little luck Sad

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: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

As an aside, any empty paragraphs left in posts are displayed like this:

<p>&nbsp;</p>

And that makes it easier to target. The problem is that I need it to only remove the empty paragraphs at the end of a post and leave any in the middle of content as they are which complicates things. I had to concede to let users be sensible with their posts and let mods and admins deal with bad inputs.

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: 4,759
Thanks: 1,049
Fixes: 27
Registered: 16-10-2014

Re: I thought that excessive blank lines had been sorted

@jaread83 - OK I see that would annoy some, so what about removing anything greater than double lines?

s/<p>&nbsp;<\/>{2,}/ /g

And using this you then only need to do it on each .lia-message-body-content.

Community Gaffer
Community Gaffer
Posts: 2,853
Thanks: 1,528
Fixes: 62
Registered: 22-02-2016

Re: I thought that excessive blank lines had been sorted

Problem with that is that some users like to use double spaces (annoying I know). Can't remove them if they were intentional. I need to find a way to only remove the empty paragraphs after the content body. Bit of a head scratcher Wink

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.