# Copy Rich Text with Formatting in JS

**URL:** <https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087>\
**Category:** Get Help\
**Created:** [April 18, 2024, 7:58am UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087 "2024-04-18T07:58:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![IMTanuki](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/imtanuki/32/7751_2.png) [@IMTanuki](https://community.fibery.io/u/IMTanuki)\
**Post date:** [April 18, 2024, 7:58am UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/1 "2024-04-18T07:58:28Z")

</div>

HI - I’m writing a JS routine to copy projects within a space. I can copy the main description field for an entity, but the copied version only contains unformatted text.

Does anyone have a sample of the code to copy both the text and the formattng? I’ve been using a snippet @Yuri_BC wrote for what appears to be markdown:

```auto
async function fetchDocumentContent(documentSecret) {
    if (!documentSecret) {
        return null;
    }
    return await fibery.getDocumentContent(documentSecret, 'md');
}

let descriptionContent = null;
        if (entity[SOURCE_DESCRIPTION_FIELD] && entity[SOURCE_DESCRIPTION_FIELD].Secret) {
            descriptionContent = await fetchDocumentContent(entity[SOURCE_DESCRIPTION_FIELD].Secret);
        }

        // Set the 'Description' content for the new entity
        if (descriptionContent) {
            await fibery.setDocumentContent(newEntity[TARGET_DESCRIPTION_FIELD].Secret, descriptionContent, 'md');
        }

```

thx!

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 18, 2024, 10:48am UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/2 "2024-04-18T10:48:41Z")

</div>

> [@IMTanuki](#):
>
> the copied version only contains unformatted text

What’s missing? All formatting, or just some specific things?

---

<div class="post-metadata">

**Author:** ![IMTanuki](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/imtanuki/32/7751_2.png) [@IMTanuki](https://community.fibery.io/u/IMTanuki)\
**Post date:** [April 18, 2024, 1:54pm UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/3 "2024-04-18T13:54:34Z")

</div>

May I ask - the code above appears to be specific for markdown. Is there corresponding code for ricj=h text?

source:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/4/4f55d349f8226eaddb41f121f708f11a3f988478.png)

target:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/f/fc721ca1cd4c57becf10c183d6d1db84e4e4a5f5.png)

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 18, 2024, 2:07pm UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/4 "2024-04-18T14:07:51Z")

</div>

There are some markdown formatting elements that are not supported when copying, e.g. callout blocks

---

<div class="post-metadata">

**Author:** ![IMTanuki](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/imtanuki/32/7751_2.png) [@IMTanuki](https://community.fibery.io/u/IMTanuki)\
**Post date:** [April 18, 2024, 2:22pm UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/5 "2024-04-18T14:22:58Z")

</div>

1. Is there any documentation that spells out what is supported? I use callouts extensively, but if there is an alternative, I can switch to supported rich text.

2. Can you please confirm if the above code is correct for rich text? This seems to be specific to markdown:  
`await fibery.setDocumentContent(newEntity[TARGET_DESCRIPTION_FIELD].Secret, descriptionContent, 'md');`

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [April 18, 2024, 3:21pm UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/6 "2024-04-18T15:21:09Z")

</div>

> [@IMTanuki](#):
>
> Is there any documentation that spells out what is supported? I use callouts extensively, but if there is an alternative, I can switch to supported rich text.

I don’t think we have anything in our user guide. Will add it to the to-do list ☹

> [@IMTanuki](#):
>
> Can you please confirm if the above code is correct for rich text? This seems to be specific to markdown:  
> `await fibery.setDocumentContent(newEntity[TARGET_DESCRIPTION_FIELD].Secret, descriptionContent, 'md');`

The code looks to be syntactically correct, but the ‘md’ option is just one of several (the others being ‘html’ and ‘json’) and if you’re copying within Fibery the html option supports more formatting options than markdown I believe.

---

<div class="post-metadata">

**Author:** ![IMTanuki](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/imtanuki/32/7751_2.png) [@IMTanuki](https://community.fibery.io/u/IMTanuki)\
**Post date:** [April 18, 2024, 4:06pm UTC](https://community.fibery.io/t/copy-rich-text-with-formatting-in-js/6087/7 "2024-04-18T16:06:52Z")

</div>

Aha! Using JSON in both the fetch and set works! I haven’t tested deeply nested text, but 2 levels deep seems to work just fine.

Thanks you so much!

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/6/6c6d5881e64555d5b42d1f2e590d2a53e6599e59.png)
