From 86f4024257bbb39b9f211b86f80c8ffd016656ad Mon Sep 17 00:00:00 2001 From: Jeetu SK <128751788+JeetuSK0808@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:53:08 -0500 Subject: [PATCH] fix(code-block): keep indentation when copying highlighted code Since #245, getCodeString runs dedent() on the copy text of every code block, including shiki-highlighted ones. Highlighted children already hold the code exactly as shown, so the copy button stripped real indentation: a lone Python function or a single top-level YAML key copied as broken code. Only dedent raw string children, which is what #245 was for. Co-Authored-By: Claude Opus 5.5 --- packages/components/src/utils/shiki/lib.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/components/src/utils/shiki/lib.ts b/packages/components/src/utils/shiki/lib.ts index 1b5c57e..9ab90e0 100644 --- a/packages/components/src/utils/shiki/lib.ts +++ b/packages/components/src/utils/shiki/lib.ts @@ -51,7 +51,11 @@ function getCodeString( const codeString = getNodeText(children); - return dedent(codeString); + // Only raw string children pick up indentation from the surrounding JSX/MDX. + // Highlighted children already hold the code exactly as it is shown, so + // dedenting them would strip real indentation from the copied text (e.g. the + // body of a lone Python function or a single top-level YAML key). + return isShiki ? codeString : dedent(codeString); } function calculateCodeLinesFromHtml(html: string | undefined): number {