Problem/Motivation

In order for a local environment to properly match a live environment, FilterAutoP text format filter should ignore html comments added by twig debug and not add extra <p> tags.

Steps to reproduce

  1. Enable twig.config debug: true in development.services.yml
  2. Set 'Convert line breaks into HTML' as the last filter
  3. Add any nested entity like Media Image into the formatted text
  4. See extra p tags added

Proposed resolution

Ignore any line breaks within or directly around anything that starts with:

<!-- THEME DEBUG -->
...
<!-- BEGIN OUTPUT from '...' -->

Remaining tasks

  1. ☑ Update function _filter_autop()
  2. ☑ Add test coverage

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

'Convert line breaks into HTML' no longer adds additional paragraph tags when twig theme debugging is enabled.

Issue fork drupal-3421843

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

scott_euser created an issue. See original summary.

scott_euser’s picture

Issue summary: View changes
Status: Active » Needs work

Tests showing this is failing with:

<p>Text here
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'html' -->
<!-- FILE NAME SUGGESTIONS:
* html--node.html.twig
x html.html.twig -->
<span>Test</span></p>

Results in:

<p>Text here</p>
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'html' -->
<!-- FILE NAME SUGGESTIONS:
* html--node.html.twig
x html.html.twig -->
<p><span>Test</span></p>

Note that when you have twig debug enabled, line breaks are always added before and after the nested twig template, even with {% apply spaceless %}{% end apply %}

scott_euser’s picture

Status: Needs work » Needs review

Okay this handles it now. Avoided regex here as its getting overly complicated given the regex would need to work across lines. Figured it is more straightforward and readable to check subsequent and preceding lines.

To test this out, without change to filter.module, this now fails:

./vendor/bin/phpunit -c core/phpunit.xml --debug core/modules/filter/tests/src/Kernel/FilterKernelTest.php --filter=testLineBreakFilter

With the change to filter.module, it passes.

scott_euser’s picture

wim leers’s picture

Component: ckeditor5.module » filter.module
wim leers’s picture

Title: FilterAutoP should ignore twig.config debug html comments » filter_autop should ignore twig.config debug html comments
Issue tags: +Twig, +TX (Themer Experience)

Makes sense!

Note that only the Restricted HTML text format uses this by default. If you're using CKEditor 5, you should not be using filter_autop at all, and you can safely disable it.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for doing this! :)

scott_euser’s picture

Assigned: scott_euser » Unassigned

Thanks for the quick review! Applied your suggestions, looks like this is ready to go then. Thanks!

scott_euser’s picture

Issue summary: View changes

Updating issue summary to mark all as completed as well (forgot!)

nod_’s picture

Status: Reviewed & tested by the community » Needs work
scott_euser’s picture

Status: Needs work » Needs review

Thanks for flagging. I updated the filter to cover that now + added an additional bit to the test.

smustgrave’s picture

Can the MR be rebased please

scott_euser’s picture

I think I did grab all from 11.x and merge it in. Isn't the squashing of commits happening when this eventually gets merged in? Probably I am not understanding what you are asking @smustgrave sorry :)

smustgrave’s picture

Appears to be failing unit tests but have seen that resolved with a rebase.

scott_euser’s picture

Ah I see, thanks!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Seeing green now

Ran the test-only feature https://git.drupalcode.org/issue/drupal-3421843/-/jobs/995505 and it failed as expected.

Appears feedback has been addressed with regards to #11.

Looks good!

scott_euser’s picture

Ah nice, handy feature; saw that 'Downstream failure' and got curious. Thanks for jumping in and helping get this one ready again!

catch’s picture

Status: Reviewed & tested by the community » Needs review

One question on the MR.

scott_euser’s picture

@catch added a suggested route instead of making it more generic - what do you think?

smustgrave’s picture

Status: Needs review » Needs work

@scott_euser seemed to got the thumbs up for that approach

scott_euser’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Did a rebase and that unit failure went away. Seen that on a few slightly older tickets.

From what I can tell feedback has been addressed and the update didn't break the changes added in #3420709: Make it more obvious that a Twig template is overridden

  • nod_ committed 6ac42007 on 11.x
    Issue #3421843 by scott_euser, smustgrave, Wim Leers, catch:...

  • nod_ committed 26a5b7e6 on 10.3.x
    Issue #3421843 by scott_euser, smustgrave, Wim Leers, catch:...

  • nod_ committed 50340b46 on 10.2.x
    Issue #3421843 by scott_euser, smustgrave, Wim Leers, catch:...

nod_’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 6ac4200 and pushed to 11.x. Thanks!

  • nod_ committed a9f0bc00 on 10.2.x
    Revert "Issue #3421843 by scott_euser, smustgrave, Wim Leers, catch:...
nod_’s picture

Version: 10.2.x-dev » 10.3.x-dev

Tests fail on 10.2.x, won't backport there. Please open a 10.2.x MR for it if it's important to have on that version.

scott_euser’s picture

Great thank you both!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.