wpDiscuz - WordPress Comment Plugin
All comment body in...
 
Share:
Notifications
Clear all

All comment body inside one paragraph

11 Posts
4 Users
1 Likes
891 Views
szmigieldesign
Posts: 5
Topic starter
(@szmigieldesign)
Active Member
Joined: 2 years ago

Hi,

it seems that when adding a reply from WP Dashboard, wpDiscuz no longer (since v7) applies paragraphs for line breaks in content (no wpautop() being run?). Despite having multiple lines, comment body is displayed in HTML as one paragraph.

What's interesting is that comments added the same way (from Dashboard) with versions prior to v7 are displayed correctly as having multiple paragraphs (although there's no spacing but that's a minor CSS issue).

Also - I've tried editing the comment by manually adding < p > tags but the comment is still displayed as one constant text inside one paragraph. Is it by design or is it a bug?

Topic Tags
10 Replies
lflier
Posts: 3
(@lflier)
New Member
Joined: 2 years ago

Yes, I have the same complaint. The behavior in standard WordPress comments is that if you hit "Return" once at the end of a paragraph the line ends with a "<br>." But if you hit "Return" twice Wordpress creates a "<p>".

But even this behavior is clunky. Everywhere else -- including right here in this reply form -- a "Return" produces a new paragraph. 

In wpDiscuz v. 7, the behavior is even less intuitive. Hitting "Return" twice at the end of a line just produces a second "<br>". The result of that is just ugly -- big gaps between paragraphs.

I will not upgrade to v.7 until this is addressed. The behavior I want is that a single "Return" produces a new paragraph.

Reply
1 Reply
szmigieldesign
(@szmigieldesign)
Joined: 2 years ago

Active Member
Posts: 5

@lflier yes, this is strange. I mean - why bother with rich editor if whole text is jammed in one paragraph. This is extremely unreadable, especially in long comments and discussions.

Reply
Tom
Posts: 486
 Tom
Support
(@tomson)
Honorable Member
Joined: 7 years ago

Hi @lflier & @szmigieldesign,

I have no idea how you get that problem. Maybe you use an old version of wpDiscuz, maybe your theme has a hard CSS affection on comment section. In any case, you should provide a direct link to that page where we can see the issue.

Currently, there is no such problem in wpDiscuz, please see the GIF video, and test on the demo:

 

 

 

 

Reply
4 Replies
szmigieldesign
(@szmigieldesign)
Joined: 2 years ago

Active Member
Posts: 5

@tomson can you confirm that adding a reply via WordPress Dashboard also results in correct formatting? I.e. is wpautop() being triggered?

Reply
Asti
 Asti
Support
(@asti)
Joined: 5 years ago

Illustrious Member
Posts: 5516

yes, @szmigieldesign, the wpautop() is always being triggered.

Reply
szmigieldesign
(@szmigieldesign)
Joined: 2 years ago

Active Member
Posts: 5

@asti do you have any ideas what I might want to check in order to debug this issue? I also tried editing the post via the frontend and while on edit view it's nicely separated, it's being displayed inside one < p > tag.

Which means that it's saved with line breaks in database but must be processed somewhere before it's displayed.

Reply
lflier
(@lflier)
Joined: 2 years ago

New Member
Posts: 3

Hi @tomson,

Here's what I'm seeing when I attempt to reproduce your video example:

Screen Shot 2020 06 16 at 7.11.55 AM
Screen Shot 2020 06 16 at 7.12.54 AM

The output is as @szmigieldesign has described. The entire comment is contained within a single <p> tag. In the HTML output, "paragraphs" are just lines separated by <br> tags.

Why is this a problem? Well, for starters, <br> tags cannot be formatted with CSS. It's impossible to add margins or padding between paragraphs when there are no paragraphs. Another problem is that if you want to increase the line spacing in the <p> tag you wind up with impossibly wide spacing where there are double <br> tags. 

A workaround is suggested by the filter in class.WpdiscuzCore.php at line 548. Using the filter, it's possible to replace line breaks in the comment text like this:

add_filter('comment_text', 'replace_comment_line_breaks' );

function replace_comment_line_breaks($comment_content) {
  $eols = array("\n","\r","\r\n");
$comment_content = str_replace($eols,'</p><p>', $comment_content);
return $comment_content;
}

I tried wpautop() in the above function but I can't get it working:

$comment_content = wpautop( $comment_content );

One problem with this code is that it produces empty paragraphs between line 2 and line 3, in the example above. I don't have time right now to work on that, but I thought I would post it as a start toward solving the problem.

Reply
Tom
Posts: 486
 Tom
Support
(@tomson)
Honorable Member
Joined: 7 years ago

I'd recommend remove all custom codes and wait for the upcoming 7.0.3 version to avoid any conflicts.

Reply
szmigieldesign
Posts: 5
Topic starter
(@szmigieldesign)
Active Member
Joined: 2 years ago

I'm happy to report that 7.0.3 fixed this issue for me.

Reply
lflier
Posts: 3
(@lflier)
New Member
Joined: 2 years ago

That's the expected behavior -- new paragraphs at double "Returns".

If anyone wants to get rid of <br> tags altogether and format every new line as a new paragraph, this filter seems to work:

add_filter('comment_text', 'replace_comment_line_breaks' );

function replace_comment_line_breaks($comment_content) {
$comment_content = preg_replace( "/[^ -~]{4}/", "<p></p>", $comment_content );
$comment_content = preg_replace( "/\x0a/", "<p></p>", $comment_content );
return $comment_content;
}

 

Reply
Share: