Skip to content

CodeBlock mis-indents string children in MDX #226

@restorenode

Description

@restorenode

Describe the bug
CodeBlock renders incorrect indentation for MDX string children wrapped in {...}.

To Reproduce

  1. Render this MDX:
<CodeBlock filename="example.ts" language="ts">
{`import {
  a,
  b,
} from 'pkg';

async function main() {
  console.log('hello');
}`}
</CodeBlock>
  1. Open the rendered page.
  2. Observe the indentation of the lines inside the code block.

Expected behavior
The code should render with the same indentation as written in the string:

import {
  a,
  b,
} from 'pkg';

async function main() {
  console.log('hello');
}

Screenshots
Image

Device:

  • OS: macOS
  • Browser: Chrome
  • Version: latest

Additional context
Raw code inside <CodeBlock>...</CodeBlock> causes MDX parsing issues, so wrapping the code in {...} is required. The source string indentation is correct, but the rendered output still appears mis-indented.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions