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

Question: How to render a dynamic string variable in code section? #3468

Open
Tracked by #2600
fkapsahili opened this issue Oct 16, 2024 · 0 comments
Open
Tracked by #2600

Question: How to render a dynamic string variable in code section? #3468

fkapsahili opened this issue Oct 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@fkapsahili
Copy link

fkapsahili commented Oct 16, 2024

Is there a way to render a variable as a string in a code block with syntax highlighting? The following code probably best describes what we have in mind:

import {Tabs, Pre, Playground} from 'nextra/components';
import Button from '@/components/ui/Button';
import ButtonSource from '!raw-loader!@/components/ui/Button';

# Button

Displays a button component.

<Tabs items={['Preview', 'Code']} defaultIndex="0">
  <Tabs.Tab>
        <Button>
            Button Preview
        </Button>
  </Tabs.Tab>

  <Tabs.Tab>
    # Here it should render the string contents correctly with syntax highlighting.
    # But this won't work, as the variable `ButtonSource` in the curly brackets is interpreted as regular code.
    ```tsx
   {ButtonSource}
    ```
  </Tabs.Tab>
</Tabs>

I think this must be somehow possible but I did not find a solution yet that works with correct syntax highlighting of the Button component's TypeScript code. When I try to render it manually using Nextra's Pre and Code components, it renders the string content of the ButtonSource variable correctly, but obviously without correct syntax highlighting:

<Pre>
  <Code>
    {ButtonSource}
  </Code>
</Pre>

Does anyone have an idea how we could achieve this?

@fkapsahili fkapsahili added the bug Something isn't working label Oct 16, 2024
@fkapsahili fkapsahili changed the title Render a string variable in code section Question: How to render a dynamic string variable in code section? Oct 16, 2024
Repository owner deleted a comment Oct 28, 2024
@dimaMachina dimaMachina mentioned this issue Nov 2, 2024
44 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant