Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#7706 closed defect (bug) (fixed)

Using nl2br for Email content adds unwanted br tags

Reported by: chherbst's profile chherbst Owned by: djpaul's profile DJPaul
Milestone: 3.0 Priority: normal
Severity: normal Version:
Component: Emails Keywords: reporter-feedback
Cc: chris.p.herbst@…

Description

When including markup in the email body, e.g. tables these are usually saved by the wordpress editor with newlines after each tag. These newlines get converted by nl2br to br tags. As br tags are not allowed between e.g. <tr> and <td> tags these get pulled in front of the table by most browsers and email clients. This leads to a lot of br tags in front of the table and thus an unusual bog amount of white space.

The attached patch uses the wordpress function wpautop instead of nl2br which replaces newlines with paragraphs and does not replace newlines inside HTML tags.

Attachments (1)

0001-use-wpautop-instead-of-nl2br-in-email-content.patch (1.7 KB) - added by chherbst 7 years ago.

Download all attachments as: .zip

Change History (7)

#1 @DJPaul
7 years ago

  • Keywords reporter-feedback added
  • Milestone changed from Awaiting Review to Under Consideration

If you're using a custom email template, can you upload that so I can test with it?
Otherwise, can you find the relevant email post type in the database, and copy out the post_content into a text file and share here?

This way, I can recreate easily what you're seeing. Ta.

#2 @chherbst
7 years ago

We are using the standard email template. The Bug occures e.g. with the following email content:

Below this text many br tags are generated:
<table>
<thead>
<tr>
<th>Heading1</th>
<th>Heading2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content1</td>
<td>Content2</td>
</tr>
</tbody>
</table>
Last edited 7 years ago by chherbst (previous) (diff)

#3 @chherbst
7 years ago

  • Cc chris.p.herbst@… added

#4 @DJPaul
7 years ago

  • Milestone changed from Under Consideration to 3.0

Yep @chherbst -- your sample code made it easy to confirm, and your patch easy to fix. Thank you so much!

#5 @djpaul
7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

In 11895:

Emails: use wpautop() instead of nl2br() when rendering HTML email content.

When including markup in the email body, e.g. tables, these are usually saved by
the WordPress editor with newlines after each tag. These newlines get converted
by nl2br() to <br> tags. As <br> tags are not allowed between all elements,
e.g. <tr> and <td>, these get pulled in front of the table by most browsers
and email clients.

This leads to a lot of <br> tags in front of the table -- undesired whitespace.

Fixes #7706

Props chherbst

#6 @DJPaul
7 years ago

And your ticket description made a fab commit message! If only all tickets were this good!

Note: See TracTickets for help on using tickets.