rehype-pretty-code icon indicating copy to clipboard operation
rehype-pretty-code copied to clipboard

Pass variable as content in MDX ?

Open aaronlin0122 opened this issue 3 years ago • 1 comments

I want to pass a variable to rehype-pretty-code as content in MDX, something like this:


```mdx title="Demo.mdx"
{frontmatter.rawmdx}
\```

frontmatter.rawmdx is created by astro-m2dx

Is It possible?

some imagine syntax:


```mdx title="Demo.mdx" content={frontmatter.rawmdx}
\```

aaronlin0122 avatar Nov 21 '22 22:11 aaronlin0122

I don't think metastrings can contain variable content; they're just raw strings.

What we can do is allow a map of the variable content in the options:

const options = {
  contentMap: {
    test: '// comment',
  }
};
```js contentKey="test"
```

Would this work?

atomiks avatar Jun 24 '23 03:06 atomiks

Best option now is just to use a component to pass runtime values (server or client): https://rehype-pretty-code.netlify.app/#react-server-component

atomiks avatar Feb 03 '24 03:02 atomiks