setData strips out <code> tags
📝 Provide detailed reproduction steps (if any)
Trying to run commentEditor.setData("<p>test comment</p><code class=\"python-code\">def withCodeBlock:<br /> print('test')</code>"); results in the <code> tags being stripped out
✔️ Expected result
Editor should contain data:
<p>test comment</p>
<code class="python-code">def withCodeBlock:<br />
print('test')</code>"
❌ Actual result
Editor contains:
<p>test comment</p>
<p>def withCodeBlock:<br>
print('test')</p>
📃 Other details
- Browser: Chrome
- OS: MacOSX 11.2.3
- First affected CKEditor version: using CKEditor5
- Installed CKEditor plugins: ["alignment:left", "alignment:right", "alignment:center", "alignment:justify", "alignment", "undo", "redo", "blockQuote", "bold", "codeBlock", "selectAll", "fontColor", "fontFamily", "fontSize", "heading", "highlight:yellowMarker", "highlight:greenMarker", "highlight:pinkMarker", "highlight:blueMarker", "highlight:redPen", "highlight:greenPen", "removeHighlight", "highlight", "horizontalLine", "htmlEmbed", "imageTextAlternative", "uploadImage", "imageUpload", "insertImage", "imageInsert", "resizeImage:original", "resizeImage:25", "resizeImage:50", "resizeImage:75", "resizeImage", "imageResize", "imageStyle:full", "imageStyle:side", "indent", "outdent", "italic", "link", "linkImage", "numberedList", "bulletedList", "mediaEmbed", "specialCharacters", "strikethrough", "subscript", "superscript", "insertTable", "tableColumn", "tableRow", "mergeTableCells", "tableCellProperties", "tableProperties", "underline"]
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
Hi! The inline <code> is a basic text formatting option that doesn't support class attribute, that's why it's removed (CKEditor 5 doesn't allow elements and attributes that are not introduced by plugins).
However, your example indicates that the code block is something that might better fit your use case, so check the code blocks feature documentation to learn more.
I am utilizing the codeblock plugin, it's what added the class to begin with as shown in the docs. This should not be inline yet it's still being stripped. Even when I try
commentEditor.setData("<p>test comment</p><code>def withCodeBlock:<br /> print('test')</code>"); the result is still the same <p> tags.
I found my issue, my sanitizer was removing the wrapping <pre> tags,
commentEditor.setData("<p>test comment</p><pre><code class=\"python-code\">def withCodeBlock:<br /> print('test')</code></pre>");
works fine.