Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas Moltzen-Bildsøe 18 posts 149 karma points
    Jul 25, 2024 @ 08:56
    Thomas Moltzen-Bildsøe
    0

    Copying content from RTE to another removes attributes

    Hi,

    I'm having trouble with copying content from one RTE property to another, in Umbraco 10.7.0.

    I have two RTE properties on the same document type. One of the RTE's is used for the text visible on the published page and the other for pre-created snippets of text from which the user copies some to the first one.

    If the user copies a single paragraph ie:

    <p class="bluetext">this is blue text</p>
    

    from one RTE to another, the class-attribute is removed.

    <p>this is blue text</p>
    

    If multiple paragraphs is copied the class-attributes are preserved:

    <p class="bluetext">this is blue text</p>
    <p class="bluetext">this is blue text</p>
    

    Is this something that can be configured?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Jul 25, 2024 @ 14:49
    Huw Reddick
    0

    Can't say I have ever come across this behaviour, and it seems to work as expected for me.

    What version of Umbraco are you using?

  • Thomas Moltzen-Bildsøe 18 posts 149 karma points
    Jul 29, 2024 @ 11:46
    Thomas Moltzen-Bildsøe
    0

    Umbraco 10.7.0 - I haven't come across this either - it is very strange indeed.

    We've migrated from 7 to 10 and it wasn't a problem before but is now.

  • Thomas Moltzen-Bildsøe 18 posts 149 karma points
    Sep 06, 2024 @ 08:54
    Thomas Moltzen-Bildsøe
    1

    So I continued on, looking into this. And two things occurred to me.

    1. We rarely put classes on the p-tags, often we want to color parts of the text, not that often paragraphs. So the classes will usually be on spans and not paragraphs
    2. When copying text with parts of the text colored using spans, this coloring will be removed as well.

    After diving into the source code, I found a setting on the TinyMCE RTE called "paste_process", which was calling a function called cleanupPasteData. This can be overwritten in appsettings.json under the RichTextEditor-property.

    function cleanupPasteData(plugin, args) {
    
      // Remove spans
      args.content = args.content.replace(/<\s*span[^>]*>(.*?)<\s*\/\s*span>/g, "$1");
    
      // Convert b to strong.
      args.content = args.content.replace(/<\s*b([^>]*)>(.*?)<\s*\/\s*b([^>]*)>/g, "<strong$1>$2</strong$3>");
    
      // convert i to em
      args.content = args.content.replace(/<\s*i([^>]*)>(.*?)<\s*\/\s*i([^>]*)>/g, "<em$1>$2</em$3>");
    
    }
    

    appsettings.json - configuration:

    "RichTextEditor": {
            "CustomConfig": {
              "paste_preprocess": "",
            }
          },
    
Please Sign in or register to post replies

Write your reply to:

Draft