Use modern HTML5 parser

Created on 2 February 2024, 10 months ago
Updated 9 April 2024, 8 months ago

Problem/Motivation

Module does not work because $html = Html::load($html) parse HTML from settings Form and tries to nest tags

Steps to reproduce

After entering the following string in the settings form:

<br> <p> <h2> <h3> <h4> <h5> <h6> <strong> <em> <sup> <blockquote> <a href> <ul> <ol start> <li> <table> <tr> <td rowspan colspan> <th rowspan colspan> <thead> <tbody> <tfoot> <caption> <drupal-media data-entity-type data-entity-uuid__zqh2vxqbk1cg__alt>

The following is how the html is loaded and parsed into a DOMDocument:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html><body><br/> <p> </p><h2> <h3> <h4> <h5> <h6> <strong> <em> <sup> <blockquote> <a href=""> <ul> <ol start=""> <li/> <table/> <tr/> <td rowspan="" colspan=""/> <th rowspan="" colspan=""/> <thead/> <tbody/> <tfoot/> <caption> <drupal-media data-entity-type="" data-entity-uuid="" alt=""/></caption></ol></ul></a></blockquote></sup></em></strong></h6></h5></h4></h3></h2></body></html>

You'll notice that there are only 3 childnodes of the body tag and nearly everything is nested inside h2>h3>h4>h5>h6

This means that the only tags working with this module currently are br, p and h2.

Proposed resolution

Use masterminds/html5 instead of DOMDocument to parse and output HTML in the FilterAllowed::getHTMLRestrictions() method. The module should match Drupal core 10.2's Drupal\filter\Plugin\Filter\FilterHtml::getHTMLRestrictions().

See Drupal core issue πŸ› Upgrade filter system to HTML5 Fixed , and the associated code change in the relevant file:

https://git.drupalcode.org/project/drupal/-/commit/201ae2e#ab8b36ae617d0...

Remaining tasks

  • Review
  • Merge

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rsnyd

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024