Closed neil-morgan closed 2 years ago
Hey @neil-morgan, i think it would be a bit overkill to add a full HTML entity resolver to this lib, but what i could do is expose a textResolver
via options, that gets called on all text nodes and that by default does nothing. You could then hook into that and run e.g. html-entities' decode()
function on the text. Would that help?
@claus if I am understanding you correctly I think that would be a massive help.
Essentially in an example like this:
render(content.body, {
nodeResolvers: {
[NODE_PARAGRAPH]: children => <Paragraph>{children}</Paragraph>,
[NODE_UL]: children => <List>{children}</List>,
[NODE_OL]: children => (
<OrderedList component="ol">{children}</OrderedList>
),
[NODE_LI]: children => <ListItem>{children}</ListItem>
},
markResolvers: {
[MARK_LINK]: (children, props) => (
<Link href={props.href}>{children}</Link>
)
}
})
It would be great to be able to resolve HTML entities wherever {children} is rendered.
Yeah there would be a new textResolver
, and all you'd have to do is:
render(doc, {
textResolver: (string) => decode(string)
})
I haven't tested this yet, will do over the long weekend.
If I am getting this right would you then have something like the below?
render(doc, {
textResolver: string => decode(string),
nodeResolvers: {
[NODE_PARAGRAPH]: children => <Paragraph>{children}</Paragraph>
}
});
Yes, exactly
@neil-morgan I published 2.5.1 with the new textResolver
option, let me know if that works for you.
@claus works perfectly. Thank you very much for your effort on this and the project as a whole.
For example a richtext string like this in storyblok...
When resolved like this...
Will still render the html entity...