From 2097369d42fed99e932dd24c8d546d4c8def89f0 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Mon, 9 Jun 2025 16:16:16 -0400 Subject: [PATCH] fix(ui): Only copy CodeBlock expandable content Prior to this change all `code` elements would be copied, so if the markdown content inside a expandable alert included single-backtick style `whatever` nodes, those would end up in the copied content. The intention of this component is definitely intended to just copy the CodeBlock content. --- src/components/codeBlock/index.tsx | 2 +- src/components/expandable/index.tsx | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/codeBlock/index.tsx b/src/components/codeBlock/index.tsx index c0fb3809e95a5..840ddc17487a6 100644 --- a/src/components/codeBlock/index.tsx +++ b/src/components/codeBlock/index.tsx @@ -58,7 +58,7 @@ export function CodeBlock({filename, language, children}: CodeBlockProps) {
Copied
-
+
{makeKeywordsClickable(makeHighlightBlocks(children, language))}
diff --git a/src/components/expandable/index.tsx b/src/components/expandable/index.tsx index 00bf1ca1b61d8..b94aae6b7e12b 100644 --- a/src/components/expandable/index.tsx +++ b/src/components/expandable/index.tsx @@ -80,8 +80,9 @@ export function Expandable({ emit('Copy Expandable Content', {props: {page: window.location.pathname, title}}); - // Attempt to get text from markdown code blocks if they exist - const codeBlocks = contentRef.current.querySelectorAll('code'); + // Attempt to get text from markdown code blocks if they exist. Only + // targets CodeBlock components using the data-codeblock marker. + const codeBlocks = contentRef.current.querySelectorAll('[data-codeblock]'); let contentToCopy = ''; if (codeBlocks.length > 0) {