From fc11b9670dcae87c4afa20c829dfa7d25d01bdbf Mon Sep 17 00:00:00 2001 From: Thomas Osmonson Date: Tue, 11 Aug 2020 17:33:01 -0500 Subject: [PATCH] fix: better code copy --- src/components/mdx/components/code.tsx | 12 ++++++++++-- src/pages/smart-contracts/counter-tutorial.md | 1 - src/pages/smart-contracts/testing-contracts.md | 1 - 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/components/mdx/components/code.tsx b/src/components/mdx/components/code.tsx index ca3757cf..622f9f75 100644 --- a/src/components/mdx/components/code.tsx +++ b/src/components/mdx/components/code.tsx @@ -50,7 +50,7 @@ export const Code: React.FC< const convertSingleChildToString = child => onlyText(child).replace(/\n/g, ''); const tokenLines = Children.toArray(children).map(convertSingleChildToString); - const codeString = tokenLines.filter(line => line !== '').join('\n'); + const codeString = tokenLines.join('\n').replace(/\n\n\n/g, '\n\n'); const { hasCopied, onCopy } = useClipboard(codeString); @@ -77,6 +77,9 @@ export const Code: React.FC< }, counterReset: 'line', '& .token-line': { + '&__empty': { + height: '24px', + }, '.comment': { color: 'rgba(255,255,255,0.5) !important', }, @@ -93,6 +96,7 @@ export const Code: React.FC< mr: '16px', width: '42px', fontSize: '12px', + transform: 'translateY(1px)', borderRight: '1px solid rgb(39,41,46)', } : {}, @@ -111,7 +115,11 @@ export const Code: React.FC< position="absolute" color="transparent" top="16px" - left={lines <= LINE_MINIMUM || lang === 'bash' ? '20px' : '58px'} + left={ + lines <= LINE_MINIMUM || lang === 'bash' + ? space(['extra-loose', 'extra-loose', '20px', '20px']) + : '58px' + } zIndex={99} > {codeString} diff --git a/src/pages/smart-contracts/counter-tutorial.md b/src/pages/smart-contracts/counter-tutorial.md index aa33f410..f90e1c97 100644 --- a/src/pages/smart-contracts/counter-tutorial.md +++ b/src/pages/smart-contracts/counter-tutorial.md @@ -70,7 +70,6 @@ counter contract test suite 2) should increment 3) should decrement - 1 passing (734ms) 3 failing diff --git a/src/pages/smart-contracts/testing-contracts.md b/src/pages/smart-contracts/testing-contracts.md index dea8f0e3..92e71123 100644 --- a/src/pages/smart-contracts/testing-contracts.md +++ b/src/pages/smart-contracts/testing-contracts.md @@ -60,7 +60,6 @@ You should see the following response: ✓ should return 'hello world' ✓ should echo number - 3 passing (412ms) ```