-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeBlock.astro
56 lines (49 loc) · 1.06 KB
/
CodeBlock.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
const identity = (x: any) => x;
const { info, print = identity, showLineNumbers } = Astro.props;
const lineNumbers = Array.from([...Array(info.length).keys()]);
---
<style is:global>
.code-wrapper {
width: 100%;
display: flex;
border-radius: 0.375rem;
overflow: hidden;
}
.code-wrapper pre {
margin: 0;
padding: 1rem 0.2rem;
border-radius: 0;
}
.code-wrapper .line-num pre {
background-color: inherit;
text-align: right;
}
.code-wrapper .code-info pre {
text-align: center;
}
.code-wrapper .code {
background-color: #24292e;
flex-grow: 1;
overflow: scroll;
}
.code-wrapper .code > pre {
padding: 1rem 1.5rem;
}
</style>
<div class="code-wrapper">
{
showLineNumbers && (
<div class="line-num">
<pre>{lineNumbers.map((num) => `${num + 1}\n`)}</pre>
</div>
)
}
<div class="code-info">
<pre>{info.map((d: any) => {
const text = d ? `${print(d)}` : " ";
return `${text}\n`;
})}</pre>
</div>
<div class="code"><slot /></div>
</div>