Repository navigation
fix(code-block): keep indentation when copying highlighted code - #271
Open
JeetuSK0808 wants to merge 1 commit into
Open
JeetuSK0808 wants to merge 1 commit into
JeetuSK0808 wants to merge 1 commit into
Conversation
Since mintlify#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 mintlify#245 was for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Since #245,
getCodeStringinpackages/components/src/utils/shiki/lib.tsrunsdedent()on the copy text of every code block, including shiki-highlighted ones. The dedent was meant for raw string children inside JSX/MDX, which pick up indentation from the surrounding markup. Highlighted children already hold the code exactly as it is shown, so the copy button strips real indentation from them. The block renders correctly, but what gets copied is broken:def handler(event):followed by an indentedreturn {"ok": True}copies with thereturnat column 0. A lone Python function or class becomes anIndentationError.This change only dedents raw string children (
isShiki ? codeString : dedent(codeString)). The cases from #226 that #245 fixed still work.Test Plan
getCodeStringon highlighted children built with shiki 3.21 for 2,000 generated snippets (Python, YAML and others), comparing the copied text with what is displayed. Python was checked withast.parseand YAML with js-yaml.pnpm lint(biome) andpnpm buildpass.🤖 Generated with Claude Code
Note
Low Risk
Narrow change to copy-text extraction in
getCodeString; display and non-Shiki dedent behavior are unchanged.Overview
Copying from highlighted code blocks again preserves the indentation shown on screen.
getCodeStringstill returns early for Shiki-rendered blocks in the normal path, but when copy forces extraction (forceExtract: true) it no longer runsdedent()on that text—only on raw string MDX/JSX children that pick up markup padding.Raw string blocks keep the #245 behavior so pasted snippets stay left-aligned without stray leading spaces.
Reviewed by Cursor Bugbot for commit 86f4024. Bugbot is set up for automated code reviews on this repo. Configure here.