-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to pass content as prop #129
Comments
@atsuyaourt Thank you for pointing this out. I see the problem, currently RichTextRenderer.astro only allows content be passed as children The solution provided is one of the ways, though I am not super sure if this is the most intuitive way. However, adding some JSDoc comments as a clear explanation should help the users out. We should not forget an example in Let me take a look into alternatives. |
I stumbled upon the exact same issue! 😅 Some random thoughtsUsing In order for this to be possible:
WDYT? |
Hey guys, we surely need to solve this somehow 💪 I was thinking of either going the way the Maybe
There is also |
Thank you so much for these insights! I agree that exposing the whole Node object is a better approach to solving this issue. The PR looks good to me, and I can't wait to try it asap! |
Getting back to this issue, it seems the heading: ({ attrs: { level }, content }) => ({
component: Text,
props: {
variant: `h${level}`,
text: content?.[0].text, // here we cannot handle content array easily in some case, thus this works only for some minor or end-of-tree nodes which does not contain complicated nodes.
},
}), However in complicated nodes like type ListItem = {
type: "list_item";
content?: Array<
Paragraph | Blok | BulletList | OrderedList | HorizontalRule | Image | Emoji
>;
};
type BulletList = {
type: "bullet_list";
content?: Array<ListItem>;
};
export type OrderedList = {
type: "ordered_list";
attrs: {
order: number;
};
content?: Array<ListItem>;
}; This implies that @atsuyaourt proposed idea of having We have to give this ticket a second go and maybe potentially add this handling possibility too 🤔 Re-opening ticket for now. |
As a workaround for now, we do have a custom RichTextRenderer.astro in the repository with extending of: if (type === 'bullet_list' || type === 'ordered_list') {
return <Component {...props} items={resolvedContent} />;
} and then resolvers configuration is:
|
It turns out that Astro has a built-in component that provides syntax highlighting for code blocks (
<Code />
). However, the string that needs to be converted should be passed as a prop, making it incompatible with your current implementation.The following won't work:
I've implemented a workaround by introducing a "metaprop" called
contentPropName
to specify the prop name to which the content will be passed. For instance, the following will render correctly because the component requires the content to be passed to a prop calledcode
:I can create a pull request for these changes, or perhaps you have other suggestions?
The text was updated successfully, but these errors were encountered: