Upgrade filter system to HTML5

Created on 26 February 2015, over 9 years ago
Updated 9 May 2024, about 2 months ago

Problem/Motivation

The filter system should be upgraded to HTML5 to match modern standards. All modern browsers now parse HTML5, our themes use an HTML5 doctype and so Drupal should treat HTML input and output the same way.

Steps to reproduce

Currently the filter system parses and outputs XHTML only. This causes PHP warnings when trying to parse modern tags:

>>> use \Drupal\Component\Utility\Html;
>>> Html::normalize("<p><figure><figcaption>Caption</figcaption></figure><video></video></p>");
PHP Warning:  DOMDocument::loadHTML(): Tag figure invalid in Entity, line: 1 in /var/www/html/drupal/core/lib/Drupal/Component/Utility/Html.php on line 289
PHP Warning:  DOMDocument::loadHTML(): Tag figcaption invalid in Entity, line: 1 in /var/www/html/drupal/core/lib/Drupal/Component/Utility/Html.php on line 289
PHP Warning:  DOMDocument::loadHTML(): Tag video invalid in Entity, line: 1 in /var/www/html/drupal/core/lib/Drupal/Component/Utility/Html.php on line 289
=> "<p><figure><figcaption>Caption</figcaption></figure><video></video></p>"

Also, <br /> and <img /> tags are self-closing. In HTML5, these are void elements and should be output simply as <br> and <img>.

Proposed resolution

Use masterminds/html5 instead of DOMDocument to parse and output HTML in the \Drupal\Component\Utility\Html utility class.

Remaining tasks

User interface changes

None

API changes

\Drupal\Component\Utility\Html::load(), \Drupal\Component\Utility\Html::serialize() and \Drupal\Component\Utility\Html::normalize() will parse and output HTML5 instead of XHTML. Input filters or other code that relies on this utility class will also now parse and output HTML5 instead of XHTML.

This does mean there are some minor changes to output, but these should not affect valid HTML documents. The change record contains known examples of output changes that may affect tests: https://www.drupal.org/node/3225468 β†’

Data model changes

None

Release notes snippet

The filter system has been upgraded to output HTML5. HTML output will have minor changes in some cases, for more information read the change record β†’ .

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
FilterΒ  β†’

Last updated about 4 hours ago

No maintainer
Created by

πŸ‡³πŸ‡±Netherlands daffie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024