Problem/Motivation

See parent issue https://www.drupal.org/project/drupal/issues/2925487 for Drupal 7.

When inserting an svg with ckeditor, that has a text format which automatically converts linebreaks to
and

, svg elements can become broken because the linebreak withing the element is replaced by a
tag.

This issue also occurs when trying to insert a fontawesome icon as svg via the fontawesome contrib module.

Example:

<svg height="333" width="333" xmlns="http://www.w3.org/2000/svg">
     <line style="stroke:rgb(255,0,0);stroke-width:3" x1="0" x2="333" y1="0" y2="333"></line>
</svg>

Proposed resolution

In the "_filter_autop" method, the svg tag needs to be included in the ignored chunks.

$chunks = preg_split('@(<!--.*?-->|</?(?:pre|script|style|object|iframe|drupal-media|svg|!--)[^>]*>)@i', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

Comments

wtrv created an issue. See original summary.

wtrv’s picture

Added patch.

A better approach would be to allow the configuration of additional block or chunk elements from the admin interface or via code.
This way, other contrib modules could easily add their own tags.

wtrv’s picture

Status: Active » Needs review
larowlan’s picture

This will need a test.

I'd argue that putting this in via CKEditor is the wrong way of doing things, but 🤷‍♂️

larowlan’s picture

Status: Needs review » Needs work

For test coverage

millerrs’s picture

Thanks for the patch. I can confirm that it works.

In my particular case, users are using media library to embed SVGs. Having the autop filter run after the embed media filter would break certain SVGs. I agree the filter should ignore SVGs as p and br tags are not valid SVG elements.

wtrv’s picture

Updated patch to include the newly adjusted unit test.

wtrv’s picture

Status: Needs work » Needs review
nils.destoop’s picture

Status: Needs review » Reviewed & tested by the community

Seems ok for me. Marking this as reviewed

alexpott’s picture

Version: 9.2.x-dev » 9.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed b3a30bae55 to 9.4.x and a0f291955f to 9.3.x. Thanks!

Backported to 9.3.x as this is a low risk bugfix.

  • alexpott committed b3a30ba on 9.4.x
    Issue #3227821 by wtrv: Broken svg element with "Auto convert linebreaks...

  • alexpott committed a0f2919 on 9.3.x
    Issue #3227821 by wtrv: Broken svg element with "Auto convert linebreaks...

Status: Fixed » Closed (fixed)

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