-
Notifications
You must be signed in to change notification settings - Fork 2
/
Code.svelte
60 lines (54 loc) · 1.13 KB
/
Code.svelte
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
57
58
59
60
<script>
export let code = '';
export let language = '';
const unEscapeHtml = (str) => {
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, "'");
};
</script>
<pre><code>{unEscapeHtml(code)}</code>
<span>{language}</span>
</pre>
<div>
{#if $$slots.default}
<div><slot /></div>
{/if}
</div>
<style>
code,
span {
font-family: 'SFMono-Regular', Menlo, Consolas, 'PT Mono', 'Liberation Mono', Courier, monospace;
tab-size: 3;
}
pre {
position: relative;
line-height: normal;
display: block;
border-radius: 0.5rem;
margin: 0 1.5rem 0 0;
padding: 1.5rem;
overflow-x: auto;
white-space: pre-wrap;
word-wrap: break-word;
background: hsl(135, 88%, 16%);
color: hsl(120, 100%, 50%);
font-size: 0.75rem;
}
span {
position: absolute;
right: 1rem;
bottom: 1rem;
font-size: 0.8rem;
color: hsl(120, 50%, 50%);
}
div {
/* caption text */
font-size: 0.8rem;
color: hsl(120, 50%, 45%);
margin: 0.5rem 1rem 0.5rem 0;
}
</style>