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
Comment #2
wtrv commentedAdded 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.
Comment #3
wtrv commentedComment #4
larowlanThis will need a test.
I'd argue that putting this in via CKEditor is the wrong way of doing things, but 🤷♂️
Comment #5
larowlanFor test coverage
Comment #6
millerrs commentedThanks 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.
Comment #7
wtrv commentedUpdated patch to include the newly adjusted unit test.
Comment #8
wtrv commentedComment #9
nils.destoop commentedSeems ok for me. Marking this as reviewed
Comment #10
alexpottCommitted 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.