Parse rich text response


When you request a rich text field from the API, you get the response like a raw string, for instance: richTextContent: "## Heading2\n*List item 1\n*List item 2\n### Heading 3".

I know the options for rendering this directly as html. However, I am interested in extracting each node of this rich text before rendering. Are there any functions to parse a rich text string into an object? So I could use the string in the example above like:

{ type: "h2", content: "Heading 2"},
{ type: "list", content: [
    { type: "listItem", content: "List item 1"},
    { type: "listItem", content: "List item 2"}
{ type: "h3", content: "Heading 3 }

for instance.

I know there are such options in Contentful.

In case there is no way to natively handle this in Strapi - do you know of any external plugins or npm-packages that could help accomplish this?

Thanks in advance!

1 Like

We went ahead and used @contentful/rich-text-from-markdown for this. Would have preferred something from Strapi though…