Skip to content

Commit

Permalink
fix: ensure right code is copied (#612)
Browse files Browse the repository at this point in the history
first/last pre isn't enough, as there can be nested pre tags due to shiki

Fixes #611
  • Loading branch information
dummdidumm authored Oct 24, 2024
1 parent e6a4c60 commit 45a42f5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/site-kit/src/lib/components/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
.find((node) => (node as HTMLElement).classList.contains('code-block')) as HTMLElement;
const ts = !!parent.querySelector('.ts-toggle:checked');
const code = parent.querySelector(`pre:${ts ? 'last' : 'first'}-of-type code`) as HTMLElement;
const code = parent.querySelector(
`pre[data-language]:${ts ? 'last' : 'first'}-of-type code`
) as HTMLElement;
navigator.clipboard.writeText(get_text(code));
}
Expand Down

0 comments on commit 45a42f5

Please sign in to comment.