WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 13 months ago

#27530 closed defect (bug) (duplicate)

Anchor tag wrapped around div tag would add extra paragraph tag

Reported by: Klikerko Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Editor Keywords: needs-testing has-patch
Focuses: Cc:

Description (last modified by pento)

(WordPress version 3.9-Alpha 27111)

This is HTML we added to our page editor:

<div><a href="#"><div>testing</div></a></div>

This is source result we are getting in browser:

<div><a href="#">
<div>testing</div>
<p></a></div>

For some reason <p> tag have been added. This happens every time block element is inside the anchor tag, we tried with <section> as well. When <span> is used instead all works fine.

Attachments (1)

27530.diff (699 bytes) - added by dkotter 5 years ago.

Download all attachments as: .zip

Change History (7)

#1 @samuelsidler
6 years ago

Hello! Thanks for the bug report. I actually see this same issue in 3.8.1, so it looks like it's not a new regression.

#2 @jeremyfelt
6 years ago

  • Version changed from trunk to 3.8.1

#3 @chriscct7
5 years ago

  • Keywords needs-patch needs-testing added

Can't replicate this on trunk (at 4.3.1)

@dkotter
5 years ago

#4 @dkotter
5 years ago

  • Keywords has-patch added; needs-patch removed

Was able to replicate this on the latest version of trunk (4.4-beta4-35721). The issue stems from the wpautop function. It ends up breaking the content into multiple pieces and then wraps paragraphs around each piece. The last piece in this situation ends up being </a></div>, which we don't want paragraphs around that.

I've added a patch that fixes this particular use case, basically it makes sure we don't wrap paragraphs around closing tags. I'm sure there's other ways to fix this so open to any suggestions.

Also, could see this as being a don't-fix, as technically we don't want block level elements inside inline elements, which is what's happening here. I believe HTML5 does allow that though, so might be worth fixing.

#5 @donnapep
4 years ago

Tested 27530.diff on Mac using:

Chrome 48.0.2564.116
Firefox 45.0
Safari 9.0.3

Results in the following HTML:

<div>
  <a href="#">
    <div>testing</div>
  </a>
</div>

<p> tags are no longer being added.

#6 @pento
13 months ago

  • Description modified (diff)
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #27350.

Note: See TracTickets for help on using tickets.