WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 4 months ago

#34994 new defect (bug)

HTML5 elements reformatted poorly switching between Visual & Text editors

Reported by: kristarella Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords:
Focuses: administration Cc:
PR Number:

Description

HTML5 elements get reformatted in weird ways when switching between Visual and Text (HTML) editors.

Details tag (not fully supported in browsers yet, but still shouldn't receive this behaviour IMO) gets an additional   above and below it upon each switch.

Section, article, and aside are all completely stripped of white space. This combined with the stripping of paragraph tags results in a block of run-together text within a couple of switches.

Demo:
https://cldup.com/OA6dgTmyxU.gif

I used HTML5 elements from https://www.tinymce.com/docs/demo/format-html5/ to test with.

Change History (1)

#1 @azaozz
4 years ago

  • Component changed from Editor to Formatting
  • Version 4.4 deleted

Hi @kristarella, thanks for the bug report.

This is a bug in wpautop() (both JS and PHP versions). It doesn't deal well with "block" tags that can contain other blocks when there are paragraphs in them.

Wpautop works by replacing two new lines with a <p> and one new line with a <br>. If you type any new lines just before or after the start/end block tags (like your example for <details>...</details>) wpautop may get "confused" and try to insert <p> where they don't belong. Then on switching back to the Text editor, there extra <p> are replaced with more line breaks.

The section, article, and aside tags are not processed by wpautop specifically. That's why they remain on the same line. This behaviour keeps them working relatively well when switching Text => Visual => Text. These tags should generally be avoided in the post content as they are used in many themes and having them in the posts would be improper use/nesting in many cases.

Note: See TracTickets for help on using tickets.