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

Use Nextra MDX parser in Component #3077

Open
LuciferUchiha opened this issue Jul 29, 2024 · 3 comments
Open

Use Nextra MDX parser in Component #3077

LuciferUchiha opened this issue Jul 29, 2024 · 3 comments

Comments

@LuciferUchiha
Copy link
Contributor

LuciferUchiha commented Jul 29, 2024

I have the following component where the content is a string. The string contain markdown text. How can I use the nextra parser to render this string as markdown?

Similarly to the Callout component.

The component in question:

const MessageCard = ({ role, content }: Message) => {
  return (
    <div
      className={`flex flex-row ${
        role === "assistant" ? "justify-start" : "justify-end"
      }`}
    >
      <div
        className={`p-4 max-w-[80%] rounded-lg ${
          role === "assistant"
            ? "bg-zinc-800 text-zinc-50"
            : "bg-zinc-50 text-zinc-800"
        }`}
      >
        {content}
      </div>
    </div>
  );
}
@dimaMachina
Copy link
Collaborator

rename content with children and

<MessageCard>
  # Hello

  - one
  - two

  > blockquote
</MessageCard>

@LuciferUchiha
Copy link
Contributor Author

LuciferUchiha commented Jul 29, 2024

Thx @dimaMachina unfortunatly this didn't work. Maybe for more context. MessageCard is never used in a .mdx file only in .tsx file. The "content" is the response from a ChatGPT call. This is what I tried:

type Message = {
  role: Role;
  content: string;
};

const MessageContent = ({ children }) => {
  return (
    <>
    {children}
    </>
  )
}

const MessageCard = ({ role, content }: Message) => {
  return (
    <div
      className={`flex flex-row ${
        role === "assistant" ? "justify-start" : "justify-end"
      }`}
    >
      <div
        className={`p-4 max-w-[80%] rounded-lg ${
          role === "assistant"
            ? "bg-zinc-800 text-zinc-50"
            : "bg-zinc-50 text-zinc-800"
        }`}
      >
        <MessageContent>{content}</MessageContent>
      </div>
    </div>
  );
}

Rather then using https://github.com/remarkjs/react-markdown I just want to use the already existing markdown compiler/parser.

@dimaMachina
Copy link
Collaborator

dimaMachina commented Sep 2, 2024

I think this can be fixed with new playground component #3174

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

2 participants