'CKEditor5 setData() stripping <code> tags

When I try to run

editor.setData("<p>test comment</p><code class=\"python-code\">def withCodeBlock:<br /> print('test')</code>");

The resulting editor contains the html:

<p>test comment</p>
<p>def withCodeBlock:
<br>print('test')</p>

It strips out the <code> tags, how can I stop this?



Solution 1:[1]

I found my issue, my sanitizer was removing a wrapping <pre> tag around the codeblock

editor.setData("<p>test comment</p><pre><code class=\"python-code\">def withCodeBlock:<br /> print('test')</code></pre>");

works perfect

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mitch