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

Serialize markdown inside custom components #196

Closed
ghoshnirmalya opened this issue Oct 12, 2021 · 5 comments
Closed

Serialize markdown inside custom components #196

ghoshnirmalya opened this issue Oct 12, 2021 · 5 comments

Comments

@ghoshnirmalya
Copy link

The children props inside custom components aren't serialized. Let's say that you have a Callout component like the following:

import { Box, HStack } from "@chakra-ui/react";
import React, { FC } from "react";

const Callout: FC = ({ children }) => {
  return (
    <Box p={4} rounded="sm" bg="gray.800" color="white">
      <HStack spacing={2}>
        <Box fontSize={48}>💡</Box>
        <Box>{children}</Box>
      </HStack>
    </Box>
  );
};

export default Callout;

We call it like this:

<Callout>
  Markdown oh **yeah**!! [Cool,
  right?](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
</Callout>

You will get something like this:
Screenshot 2021-10-13 at 1 52 57 AM

This issue extends this one.

@mattboon
Copy link

mattboon commented Oct 12, 2021

You could try using this fork which upgrades MDX to v2 - discussion here, which seems to handle nested markdown better in my experience.

It might work if your MDX becomes as follows, with new lines to force inline MDX transclusion:

<Callout>

Markdown oh **yeah**!! [Cool,
right?](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
  
</Callout>

Further discussions:
mdx-js/mdx#628
mdx-js/mdx#241

@jescalan
Copy link
Contributor

Afaik there is a stable release of mdx@2 coming soon, as soon as that is out we will put out a new release that supports it 😅

@ghoshnirmalya
Copy link
Author

ghoshnirmalya commented Oct 13, 2021

Awesome! Thank you @mattboon @jescalan. Should I close this issue then?

@jescalan jescalan closed this as completed Nov 3, 2021
@rome2o
Copy link

rome2o commented Jun 10, 2022

Hi @jescalan.

Mdx 2 was out earlier this year, has there been any news on this? or any examples that you could share?

Thanks

@jescalan
Copy link
Contributor

Are you having trouble getting this to work correctly?

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

4 participants