hashicorp / next-mdx-remote

Load MDX content from anywhere
Mozilla Public License 2.0
2.73k stars 141 forks source link

when using rehype-sanitize I can't render my custom component #477

Open 2820402 opened 1 month ago

2820402 commented 1 month ago
import { serialize } from 'next-mdx-remote/serialize';
import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';

const schema = {
    ...defaultSchema,
    tagNames: [
        ...defaultSchema.tagNames!,
        'Callout',
    ],
    attributes: {
        ...defaultSchema.attributes,
        Callout: ['*'],
    },
};

const source = "<Callout emoji='💡'>Testing</Callout>"

const mdxSource = await serialize(source, {
        mdxOptions: {
            remarkPlugins: [remarkGfm],
            rehypePlugins: [
                [
                    rehypeSanitize,
                    {
                        schema: schema,
                    },
                ],
            ],
            format: 'mdx',
        },
    });

console.log(mdxSource) // empty don't have Callout component

Is there is a way to render that component while using rehype-sanitize

the version I use is

"rehype-sanitize": "^6.0.0",
"next-mdx-remote": "^5.0.0",