Problem/Motivation

Comparing revisions using the visual inline diff layout, strips out HTML5 (such as <section> <article> ....etc). These elements are replaced by <div> and <span> tags and as a result the page loses styles.

Proposed resolution

The HTMLPurifier itself is stripping out these elements. Perhaps the diff module could add a feature to allow for HTML5 Definitions for the HTML Purifier. These definitions are available: https://github.com/xemlock/htmlpurifier-html5

For the patch to work or to test, you will need to install https://github.com/xemlock/htmlpurifier-html5
composer require xemlock/htmlpurifier-html5

Issue fork diff-3226910

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

adstokoe created an issue. See original summary.

adstokoe’s picture

adstokoe’s picture

For the patch to work or to test, you will need to install https://github.com/xemlock/htmlpurifier-html5
composer require xemlock/htmlpurifier-html5

adstokoe’s picture

adstokoe’s picture

Issue summary: View changes
adstokoe’s picture

Issue summary: View changes
chandraraj’s picture

@adstokoe,

Thanks for the patch. It works well.

chandraraj’s picture

Hi @phenaproxima/ @miro_dietiker

I've tested the patch. It seems to be working well for HTML5. But we need to install `xemlock/htmlpurifier-html5` package before adding the patch.

So could you please review this work and include the package in composer.json.

Thanks,
Chandra

adstokoe’s picture

Status: Active » Needs review
chandraraj’s picture

Status: Needs review » Reviewed & tested by the community
chandraraj’s picture

@alan-d @lhangea @juampynr

Please see https://www.drupal.org/project/diff/issues/3226910#comment-14188898.

So could you please review the work and include the package `xemlock/htmlpurifier-html5` in your composer.json.

Thanks

bkosborne’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.32 KB

Ran into this as well, and the change makes sense to me.
Modified patch to include the composer requirement and remove unnecessary var declaration in constructor.

bkosborne’s picture

StatusFileSize
new1.29 KB

This one has the var removal I mentioned...

bkosborne’s picture

Note that even though the patch includes the update to composer.json to bring in the new package, if you use this patch via composer patches, it will not bring in that dependency. I think it's just how composer works. You cannot bring in a patch that adds further composer deps. So you still need to explicitly add the new package to your own composer.json until this is committed.

bkosborne’s picture

StatusFileSize
new1.28 KB
druplr’s picture

Patch #15 works for me. Thanks!

steinmb’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
saltwaterskin’s picture

Re-roll for 1.1

luke.leber’s picture

Alternatively, the latest version of caxy/php-htmldiff now allows to completely turn off HTMLPurifier. Perhaps we can simply add a toggle to turn it off entirely? Drupal has its own filtering chain -- I don't see an overly compelling reason to add another one on the end of it.

$html_diff->getConfig()->setPurifierEnabled(FALSE);
luke.leber’s picture

StatusFileSize
new1.03 KB

Attaching demo patch.

luke.leber’s picture

To work around this and other issues, I've spun up https://drupal.org/project/diff_plus with a resolution for HTML5 elements as well as some other opinionated additions if any issue watchers would like to give it a try.

adriancid’s picture

reroll

acbramley’s picture

Status: Needs review » Needs work
Issue tags: -html5, -html purifier +Needs tests

This needs to go into an MR with tests.

sandipta’s picture

Along with the above mentioned things, couple of things are still getting removed
To name a few :
1. Style Attribute
2. ID's associated with Section
3. button tag
4. Attributes like aria-label, data-title, data-lity, data-toggle, aria-expanded
5. nbsp
6. iframe tag
7. Custom Data Attributes
8. Form Tag

tunic’s picture

I've tried patch from #23 and but see no improvement, the content is displayed totally broken (CSS issues). Not sure if this is because the use of layout builder, paragraphs or what. Using Drupal 10.4.4.

matthijs made their first commit to this issue’s fork.

matthijs’s picture

Version: 8.x-1.x-dev » 2.x-dev
Status: Needs work » Needs review

Disabling the purifier as suggested in #19 seems the right way to go for me. Opened an MR for it.

acbramley’s picture

Status: Needs review » Needs work

the MR is failing linting and still needs tests

mmenavas’s picture

Reroll of #22 for 8.x-1.10.