Skip to content

Conversation

@KianNH
Copy link
Member

@KianNH KianNH commented Feb 20, 2025

Summary

Use dedent in Markdown component

Screenshots (optional)

Before:
image

After:
image

@github-actions
Copy link
Contributor

Howdy and thanks for contributing to our repo. We review internal PRs with 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally.


The Markdown component uses the [`dedent`](https://www.npmjs.com/package/dedent) library to remove indentation from multi-line strings.

This is because the [Commonmark spec](https://spec.commonmark.org/0.22/#indented-code-blocks) treats indented text as code blocks, unlike [MDX](https://mdxjs.com/docs/what-is-mdx/#:~:text=Indented%20code%20does%20not%20work%20in%20MDX%3A).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is because the [Commonmark spec](https://spec.commonmark.org/0.22/#indented-code-blocks) treats indented text as code blocks, unlike [MDX](https://mdxjs.com/docs/what-is-mdx/#:~:text=Indented%20code%20does%20not%20work%20in%20MDX%3A).
This is because the [Commonmark spec](https://spec.commonmark.org/0.22/#indented-code-blocks) treats indented text as code blocks, unlike [MDX](https://mdxjs.com/docs/what-is-mdx/#:~:text=Indented%20code%20does%20not%20work%20in%20MDX%3A). If you want to author a code block, use a [\`\`\` triple backtick code fence](https://spec.commonmark.org/0.12/#fenced-code-blocks).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we'd want to avoid these, but I also don't have a good way of providing an alternative.

Code blocks from marked will just be <pre> with no styling like highlighting, no copy to clipboard, etc - but you can't just use the Code component in normal Markdown either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been just using the Code component outside the Markdown component for code blocks, and selecting the appropriate language. There are a lot of things that are fiddly inside JSX, and best dealt with the components we have for it (like AnchorHeading and Code, for example).

@github-actions
Copy link
Contributor

@KianNH KianNH merged commit d8805bb into production Feb 20, 2025
11 checks passed
@KianNH KianNH deleted the kian/PCX-16007 branch February 20, 2025 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants