Completed
Last Updated: 07 Feb 2022 14:12 by ADMIN
ADMIN
Marin Bratanov
Created on: 25 Jun 2018 09:33
Category: Editor
Type: Bug Report
0
After pasting from MS Word, StripSpan does not work until a mode change to HTML and back to Design
Repro steps: 
- use the editor below and the attached Word document in the archive at the end
- copy the document content in the editor
- clean the word formatting
- select some of the content (e.g., one paragraph)
- click the format stripper dropdown and choose Strip Span Elements
- run get_html(true) in the console

Expected: spans are stripped only from the selected content

Actual: nothing is stripped. Changing to HTML mode and back to Design fixes this, so you should not use that to check the HTML

        <telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1">
            <Tools>
                <telerik:EditorToolGroup>
                    <telerik:EditorTool Name="FormatStripper" />
                </telerik:EditorToolGroup>
            </Tools>
        </telerik:RadEditor>


WORKAROUNDS:

For the majority of cases you can set up automatic stripping of span elements when pasting from Word, so your users do not need to do that themselves. Here is an example:

<telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1"
    StripFormattingOptions="ConvertWordLists, MSWordNoMargins, Span">
    <Tools>
        <telerik:EditorToolGroup>
            <telerik:EditorTool Name="FormatStripper" />
        </telerik:EditorToolGroup>
    </Tools>
</telerik:RadEditor>

You can read more on how stripping MS Word content works in the following demo, and play around with the various options to see what works best for your case: http://demos.telerik.com/aspnet-ajax/editor/examples/cleaningwordformatting/defaultcs.aspx and in the following documentation article: https://docs.telerik.com/devtools/aspnet-ajax/controls/editor/managing-content/pasting-content/clean-ms-word-formatting

There are also two possible code workarounds so advanced users can retain more control over the HTML without switching to the HTML mode themselves.
The second is likely to be a tad faster with large content, but the first is likely to produce better user experience.

1) this changes the mode to HTML and back to design with each paste so that the stripping tool can work with the selection


<telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1"
     OnClientCommandExecuted="OnClientCommandExecuted">
    <Tools>
        <telerik:EditorToolGroup>
            <telerik:EditorTool Name="FormatStripper" />
        </telerik:EditorToolGroup>
    </Tools>
</telerik:RadEditor>
<script>
    function OnClientCommandExecuted(sender, args) {
        if (args.get_commandName() == "Paste") {
            sender.set_mode(2);
            setTimeout(function () {
                sender.set_mode(1);
            }, 50);
        }
    }
</script>

2) this one is a workaround that allows the stripping tool to work without mode change, but it will not operate with the selection but with all the content


<telerik:RadEditor RenderMode="Lightweight" runat="server" ID="RadEditor1"
     OnClientCommandExecuting="OnClientCommandExecuting">
    <Tools>
        <telerik:EditorToolGroup>
            <telerik:EditorTool Name="FormatStripper" />
        </telerik:EditorToolGroup>
    </Tools>
</telerik:RadEditor>
<script>
    function OnClientCommandExecuting(sender, args) {
        if (args.get_commandName() == "StripSpan") {
            sender.set_html(sender.get_html(true));
        }
    }
</script>
Attached Files:
1 comment
ADMIN
Rumen
Posted on: 07 Feb 2022 14:12

The issue happens because the paste scenario is not handled in the following check which transforms the span to font tag when switching between the modes and the ConvertFontToSpanFilter is enabled:

 var fontToSpanFilter = editor._filtersManager.getFilterByName("ConvertFontToSpanFilter");
 if (editor.get_mode() == Telerik.Web.UI.EditModes.Design && clearValue == SPAN && fontToSpanFilter && fontToSpanFilter.get_enabled())
 {
  clearValue = FONT;
 }

inside the FormatStripper function (0editorUtils.js). This way the pasted font tags do not get transformed to span tags and therefore the strip span option of the FormatStripper does not strip them since there are no font tags inside. The solution is to attach to the OnClientPasteHtml event, check for the Paste command and replace the span tags with font tags or directly strip the span tags.

Another approach is to disable the ConvertFontToSpan filter.


Best Regards,
Rumen
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.