Skip to content

fix(theme-classic): support nested elements inside inline code#12164

Open
MasterIfeanyi wants to merge 1 commit into
facebook:mainfrom
MasterIfeanyi:fix/code-inline-with-nested-elements
Open

fix(theme-classic): support nested elements inside inline code#12164
MasterIfeanyi wants to merge 1 commit into
facebook:mainfrom
MasterIfeanyi:fix/code-inline-with-nested-elements

Conversation

@MasterIfeanyi

Copy link
Copy Markdown
Contributor

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

When using CommonMark format, wrapping inline content that contains nested HTML elements (like <var>) inside a <code> tag incorrectly renders as a block code element instead of inline code.

For example, <code>inline <var>var</var></code> was being rendered as a <pre> block instead of staying inline.

This fixes #10533.

Test Plan

The shouldBeInline function in MDXComponents/Code.tsx previously only treated plain strings as inline-safe. This PR introduces a containsNewline helper that recursively checks nested React elements for newlines, so elements like <var> inside <code> are correctly treated as inline as long as they contain no newlines.

To verify: add This is <code>inline <var>var</var></code> to any Markdown file with CommonMark enabled and confirm it renders inline instead of as a code block.

Test links

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

Closes #10533

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jun 13, 2026
@netlify

netlify Bot commented Jun 13, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 829d9e9
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a2d2ff74a84490008e27c75
😎 Deploy Preview https://deploy-preview-12164--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using commonmark, <var> inside of <code> results in a codeblock

1 participant