I’m using the documentToHtmlString() to resolve rich text areas. I have a link to an asset that I want to resolve.
I have this code working.
import { MARKS, BLOCKS, INLINES } from '@contentful/rich-text-types';
const options = {
renderMark: {
[MARKS.BOLD]: text => `<strong>${text}</strong>`
},
renderNode: {
[INLINES.ASSET_HYPERLINK]: (node, next) => {
return `<a href="${node.data.target.fields.file.url}">${next(node.content)}</a>`;
}
}
};
And I’m calling it with return documentToHtmlString(obj, options);
And it works but it seems really clunky. Is there a better way to resolve links inside rich text?