Skip to content
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

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

Open
2820402 opened this issue Oct 10, 2024 · 0 comments
Open

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

2820402 opened this issue Oct 10, 2024 · 0 comments

Comments

@2820402
Copy link

2820402 commented Oct 10, 2024

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",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant