nascentdigital / contentfully

A simple but performant REST client for Contentful.
MIT License
18 stars 7 forks source link

Feature/adding renderRichtext option #49

Open Shenoudafarouk opened 2 years ago

Shenoudafarouk commented 2 years ago

Added the ability to HTML renderer for the Contentful rich text field type.

you can enable as follows:

const data = await contentfully.getEntries(query,  { renderRichtext: true });

so the old response was look something like this:

{
        "_id": "26sw3opeSNXmhzS9kgpfde",
        "_type": "helloworld",
        "_createdAt": "2022-02-08T15:03:27.611Z",
        "_updatedAt": "2022-02-16T17:07:27.784Z",
        "title": "Hello World",
        "richtext": [
            {
                "nodeType": "paragraph",
                "content": [
                    {
                        "nodeType": "text",
                        "value": "hallo world",
                        "marks": [
                            "italic",
                            "underline"
                        ]
                    }
                ]
            }
        ]
}

after enabling the option It should look something like this:

{
        "_id": "26sw3opeSNXmhzS9kgpfde",
        "_type": "helloworld",
        "_createdAt": "2022-02-08T15:03:27.611Z",
        "_updatedAt": "2022-02-16T17:07:27.784Z",
        "title": "Hello World",
        "richtext": "<p><u><i>hallo world</i></u></p>"
}