Telerik Editor (in Sitecore) is dropping data-* attributes during pasteHtml() call

0 Answers 56 Views
Editor
J
Top achievements
Rank 1
J asked on 19 Sep 2022, 05:37 PM

I am in the process of creating a custom action for the Editor in Sitecore, which I can see is a Telerik component.

My action builds a <span> tag around selected text containing class, data-toggle, data-target attributes like this:

<span class="myclass" data-toggle="modal" data-target="#targetid">Text</span>

It does this by building the HTML in javascript and calling (editor).pasteHtml() to replace the selected text with the annotated text.

However, I've run into cases where if there's an existing <span> tag in the backing HTML wrapping the text, all of the data-* attributes disappear.

<span style="color: #000000;">My Text</span>
<!-- converts to -->
<span style="color:#000000;" class="myclass">My Text</span>

This only happens when I select the full "My text" string between the span tags; if I select just "Text", it will work fine.  This leads me to believe that the editor wants to be smart and consolidate the span tag attributes (Good!) but either skips or ignores the data-* attributes (Boo!)

I have the following questions:

  • Is this expected behaviour from the Telerik editor, or possibly a customization implemented by Sitecore? (I'm not quite certain how to get the version of the Editor script in use here)
  • Is there an allow-list type parameter that could be configured on the editor to enable the merging of data-* attributes during the pasteHtml() call?

Thanks in advance!

No answers yet. Maybe you can help?

Tags
Editor
Asked by
J
Top achievements
Rank 1
Share this question
or