Skip to content

Commit 218d2b4

Browse files
authored
fix: copy text (#978)
1 parent f6a17a2 commit 218d2b4

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/components/Code.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,34 @@ export interface CodeBlockProps {
1414
maxHeight?: string
1515
}
1616

17-
// Direct port of https://github.com/programming-in-th/programming.in.th/blob/main/src/components/Code.tsx
18-
// May cause bug
1917
const Code = ({ code, language, maxHeight = 'auto' }: CodeBlockProps) => {
2018
return (
2119
<div className="py-2">
2220
<Highlight Prism={Prism} code={code} language={language as Language}>
2321
{({ style, tokens, getLineProps, getTokenProps }) => (
24-
<pre
22+
<div
2523
style={{ ...style, maxHeight }}
2624
className={`language-${language} overflow-y-auto rounded-lg text-[13.6px]`}
2725
>
2826
<code className={`language-${language}`}>
2927
{tokens.map((line, i) => (
30-
<tr key={i} {...getLineProps({ line, key: i })}>
31-
<td className="w-8 select-none pr-2 text-gray-500">
28+
<div
29+
key={i}
30+
{...getLineProps({ line, key: i })}
31+
className="flex"
32+
>
33+
<span className="w-8 select-none pr-2 text-gray-500">
3234
{i + 1}
33-
</td>
34-
<td>
35+
</span>
36+
<span className="flex-1">
3537
{line.map((token, key) => (
3638
<span key={key} {...getTokenProps({ token, key })} />
3739
))}
38-
</td>
39-
</tr>
40+
</span>
41+
</div>
4042
))}
4143
</code>
42-
</pre>
44+
</div>
4345
)}
4446
</Highlight>
4547
</div>

src/styles/index.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ svg {
1414
* Based on copypasta from Remy Bach and Sarah Drasner
1515
*/
1616
code[class*='language-'],
17-
pre[class*='language-'] {
17+
div[class*='language-'] {
1818
color: white;
1919
background: #011627;
2020
font-family:
@@ -46,32 +46,32 @@ pre[class*='language-'] {
4646
}
4747

4848
/* Code blocks */
49-
pre[class*='language-'] {
49+
div[class*='language-'] {
5050
overflow: auto;
5151
margin: 0.5em 0;
5252
padding: 1.3125rem;
5353
font-size: 14px;
5454
}
5555

56-
pre[class*='language-']::-moz-selection {
56+
div[class*='language-']::-moz-selection {
5757
/* Firefox */
5858
background: hsl(207, 4%, 16%);
5959
}
6060

61-
pre[class*='language-']::selection {
61+
div[class*='language-']::selection {
6262
/* Safari */
6363
background: hsl(207, 4%, 16%);
6464
}
6565

6666
/* Text Selection colour */
67-
pre[class*='language-']::-moz-selection,
68-
pre[class*='language-'] ::-moz-selection {
67+
div[class*='language-']::-moz-selection,
68+
div[class*='language-'] ::-moz-selection {
6969
text-shadow: none;
7070
background: hsla(0, 0%, 100%, 0.15);
7171
}
7272

73-
pre[class*='language-']::selection,
74-
pre[class*='language-'] ::selection {
73+
div[class*='language-']::selection,
74+
div[class*='language-'] ::selection {
7575
text-shadow: none;
7676
background: hsla(0, 0%, 100%, 0.15);
7777
}

0 commit comments

Comments
 (0)