Skip to content

fix(theme/codeblock): avoid list markers when copying code blocks - #3501

Merged
SoonIter merged 2 commits into
web-infra-dev:mainfrom
maikthomas:fix/copy-code-list-markers
Jul 7, 2026
Merged

SoonIter merged 2 commits into
web-infra-dev:mainfrom
maikthomas:fix/copy-code-list-markers

Conversation

@maikthomas

@maikthomas maikthomas commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes code-copy behavior for code blocks nested in list items.

Previously, copying a code block inside an ordered or unordered list could prepend list markers (for example, 1. or - ) to the copied text. This happened because markdown list formatting was applied during text extraction, even for code content.

This change updates the copy text extraction logic to skip markdown list marker rendering when the target is inside pre or code, so copied output is the exact code users expect.

Also included:

  • Added unit tests for getCopyableText to cover:
    • code blocks inside ordered lists (no numeric prefix),
    • code blocks inside unordered lists (no dash prefix),
    • preservation of list markers for non-code list content.

Related Issue

fixes #3500

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@SoonIter SoonIter changed the title fix(theme): avoid list markers when copying code blocks fix(theme/codeblock): avoid list markers when copying code blocks Jul 7, 2026
@SoonIter

SoonIter commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

LGTM, thanks for the fix!

@SoonIter
SoonIter merged commit 45b87c9 into web-infra-dev:main Jul 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Code block copy includes parent list marker when code block is nested in list item

2 participants