Problem/Motivation
It appears that using the "ToC Chunker" may interfere with content output, specifically if the content does not pass DomDocument's HTML validation.
Steps to reproduce
- Install and enable Sector ToC along with its dependencies
- Configure a content type to use "ToC Chunker" on the Body field at
/admin/structure/types/manage/<type>/display - Create a piece of content which uses an unrecognised HTML tag, such as
<drupal-media>,<drupal-entity-embed>, or (unconfirmed) HTML5 tags such as<command>,<details>or<figure> - View the content; when chunked, unrecognised tags will be stripped from the HTML source before the filters are applied
Proposed resolution
- Verify the reported problem, ideally by introducing test coverage
- Agree on a solution
- Implement the solution
Comments
Comment #2
xurizaemonComment #3
xurizaemonReproduction notes:
Configured the "Full HTML" format with CKEditor5, "Manually editable HTML tags" permitting additional tags ` `. It was not necessary to add ` ` as these tags were already provided by a CKEditor plugin.
Input HTML
The Body of the node was set to:
Output when Body display is set to "ToC Chunker"
Excerpted, the first paragraph outputs as:
The media in the second section is not displayed at all.
Output when Body display is set to "Chunker"
This also appears wrong - the closing tag of the
<command>container has moved to the end of the line?!Output when Body display is set to "Default"
The closing tag of the
<command>container has moved to the end of the line again. For this reason I am not (yet) moving the issue from Sector ToC to Chunker; the removal of unrecognised tags is the issue being reported here.(I expect that moving the closing </command> tag is either my own mistake, some other local configuration, or perhaps a CKEditor behaviour. Most likely the first!)
Analysis
I see that some of the HTML modification is coming from Chunker, but also that the behaviour is worse (removes Drupal media embeds) in Sector ToC.
Chunker below is processing the source HTML - so non-HTML markup such as
<drupal-*>may be visible in the source, as may be HTML5-valid tags such as<command>. It may be that Chunker should run later in the process - especially if the filters might impact the heading structure of the document.When we're in Chunker's
\Drupal\chunker\Plugin\Field\FieldFormatter\ChunkerFormatter::viewElements(), inside theforeach()on $items we have a single item, where the value is:The `#text` value of `$elements` after this foreach is set to:
In debugger output we see warnings such as:
Notes
I did investigate whether applying the change from #2441811: Upgrade filter system to HTML5 to core modified this behaviour, but it did not seem to have any impact.
Comment #4
jonathan_hunt commentedI was not able to reproduce this using Chunker formatter alone, as output format for basic page body. However, with Sector ToC the
<drupal-media>present in the body text area is not rendered. This is on a text area that is not using CKEditor5. So it's either Sector ToC or toc_api at issue...Comment #5
xurizaemonPossibility this is related to #2986763: FIX for html stripped by Xss:filterAdmin() in TocBuilder::buildContent() as well, not yet investigated (thanks @jonathan_hunt).
Comment #6
ericgsmith commentedI think the debugger warnings mentioned are fine - they are coming from https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/lib/Drupal/... which is suppressed for a reason.
I have tested using patch from #2986763: FIX for html stripped by Xss:filterAdmin() in TocBuilder::buildContent() and was not able to reproduce the issue - I strongly suspect applying the patch from 2986763 will resolve this issue. That should perhaps be added somewhere as a needed step (project page?) if confirmed.
Comment #7
xurizaemonYep, it appears that this was a manifestation of #2986763: FIX for html stripped by Xss:filterAdmin() in TocBuilder::buildContent(), thanks Eric. Applying the patch from that issue appears to have addressed this behaviour.