|
4 | 4 | import 'prismjs/components/prism-dart';
|
5 | 5 | import 'prismjs/components/prism-kotlin';
|
6 | 6 | import 'prismjs/components/prism-json';
|
| 7 | + import 'prismjs/components/prism-bash'; |
| 8 | + import 'prismjs/components/prism-yaml'; |
| 9 | + import 'prismjs/components/prism-swift'; |
7 | 10 | import 'prismjs/plugins/autoloader/prism-autoloader';
|
| 11 | + import 'prismjs/plugins/custom-class/prism-custom-class'; |
8 | 12 | import 'prismjs/plugins/line-numbers/prism-line-numbers';
|
9 | 13 | import 'prismjs/plugins/line-numbers/prism-line-numbers.css';
|
10 | 14 | import { afterUpdate } from 'svelte';
|
11 | 15 | import { Copy } from '.';
|
12 | 16 |
|
13 | 17 | export let label: string = null;
|
| 18 | + export let labelIcon: 'code' | 'android' | 'flutter' | 'apple' = null; |
14 | 19 | export let code: string;
|
15 |
| - export let language: 'js' | 'html' | 'dart' | 'kotlin' | 'json'; |
16 |
| - export let showLineNumbers = false; |
17 |
| - export let showCopy = false; |
| 20 | + export let language: 'js' | 'html' | 'dart' | 'kotlin' | 'json' | 'sh' | 'yml' | 'swift'; |
| 21 | + export let withLineNumbers = false; |
| 22 | + export let withCopy = false; |
| 23 | +
|
| 24 | + Prism.plugins.customClass.prefix('prism-'); |
18 | 25 |
|
19 | 26 | afterUpdate(async () => {
|
20 | 27 | Prism.highlightAll();
|
21 | 28 | });
|
22 | 29 | </script>
|
23 | 30 |
|
24 |
| -<div class="code"> |
25 |
| - <div class="controls"> |
| 31 | +<section class="box u-overflow-hidden common-section"> |
| 32 | + <div |
| 33 | + class="controls u-position-absolute u-inset-inline-end-8 u-inset-block-start-8 u-flex u-gap-8"> |
26 | 34 | {#if label}
|
27 |
| - <Pill>{label}</Pill> |
| 35 | + <Pill> |
| 36 | + {#if labelIcon} |
| 37 | + <span class={`icon-${labelIcon}`} aria-hidden="true" /> |
| 38 | + {/if} |
| 39 | + {label} |
| 40 | + </Pill> |
28 | 41 | {/if}
|
29 |
| - {#if showCopy} |
| 42 | + {#if withCopy} |
30 | 43 | <Copy value={code}>
|
31 |
| - <span class="icon-duplicate" aria-hidden="true" style="cursor: pointer;" /> |
| 44 | + <button class="button is-small is-text is-only-icon" aria-label="copy code"> |
| 45 | + <span class="icon-duplicate" aria-hidden="true" /> |
| 46 | + </button> |
32 | 47 | </Copy>
|
33 | 48 | {/if}
|
34 | 49 | </div>
|
35 |
| - <pre class={`language-${language}`} class:line-numbers={showLineNumbers}><code |
| 50 | + |
| 51 | + <pre class={`language-${language}`} class:line-numbers={withLineNumbers}><code |
36 | 52 | >{code}</code></pre>
|
37 |
| -</div> |
| 53 | +</section> |
38 | 54 |
|
39 | 55 | <style lang="scss" global>
|
40 | 56 | @import 'prismjs/themes/prism.css';
|
41 | 57 |
|
42 |
| - div.code { |
43 |
| - position: relative; |
| 58 | + .box { |
| 59 | + --p-box-background-color: var(--color-neutral-300) !important; |
| 60 | +
|
| 61 | + body.theme-light & { |
| 62 | + --p-box-background-color: var(--color-neutral-5) !important; |
| 63 | + } |
44 | 64 |
|
45 |
| - div.controls { |
46 |
| - position: absolute; |
47 |
| - right: 0.5rem; |
48 |
| - top: 0.5rem; |
49 |
| - z-index: 1; |
| 65 | + .controls { |
| 66 | + z-index: 2; |
50 | 67 | }
|
51 | 68 | }
|
52 | 69 |
|
|
56 | 73 | color: #fcfcff;
|
57 | 74 | text-shadow: none;
|
58 | 75 | font-family: 'Source Code Pro';
|
| 76 | +
|
| 77 | + &.line-numbers { |
| 78 | + padding-left: 2.5em; |
| 79 | + } |
59 | 80 | body.theme-light & {
|
60 | 81 | color: #373b4d;
|
61 | 82 | }
|
|
77 | 98 |
|
78 | 99 | :not(pre) > code[class*='language-'],
|
79 | 100 | pre[class*='language-'] {
|
80 |
| - background: #1b1b28; |
81 |
| - body.theme-light & { |
82 |
| - background: #fcfcff; |
83 |
| - } |
| 101 | + background: hsl(var(--p-box-background-color)); |
| 102 | + padding: 0; |
| 103 | + margin: 0; |
84 | 104 | }
|
85 |
| - .token { |
86 |
| - &.comment, |
87 |
| - &.prolog, |
88 |
| - &.doctype, |
89 |
| - &.cdata { |
| 105 | + .prism-token { |
| 106 | + &.prism-comment, |
| 107 | + &.prism-prolog, |
| 108 | + &.prism-doctype, |
| 109 | + &.prism-cdata { |
90 | 110 | color: #868ea3;
|
91 | 111 | }
|
92 | 112 |
|
93 |
| - &.punctuation { |
| 113 | + &.prism-punctuation { |
94 | 114 | color: #fcfcff;
|
95 | 115 |
|
96 | 116 | body.theme-light & {
|
97 | 117 | color: #373b4d;
|
98 | 118 | }
|
99 | 119 | }
|
100 |
| - &.property, |
101 |
| - &.tag, |
102 |
| - &.boolean, |
103 |
| - &.number, |
104 |
| - &.constant, |
105 |
| - &.symbol, |
106 |
| - &.deleted, |
107 |
| - &.selector, |
108 |
| - &.attr-name, |
109 |
| - &.string, |
110 |
| - &.char, |
111 |
| - &.builtin, |
112 |
| - &.inserted { |
| 120 | + &.prism-property, |
| 121 | + &.prism-tag, |
| 122 | + &.prism-boolean, |
| 123 | + &.prism-number, |
| 124 | + &.prism-constant, |
| 125 | + &.prism-symbol, |
| 126 | + &.prism-deleted, |
| 127 | + &.prism-selector, |
| 128 | + &.prism-attr-name, |
| 129 | + &.prism-string, |
| 130 | + &.prism-char, |
| 131 | + &.prism-builtin, |
| 132 | + &.prism-inserted { |
113 | 133 | color: #fdc584;
|
114 | 134 | body.theme-light & {
|
115 | 135 | color: #e49545;
|
116 | 136 | }
|
117 | 137 | }
|
118 |
| - &.operator, |
119 |
| - &.entity, |
120 |
| - &.url, |
121 |
| - .language-css &.string, |
122 |
| - .style &.string { |
| 138 | + &.prism-operator, |
| 139 | + &.prism-entity, |
| 140 | + &.prism-url, |
| 141 | + .language-css &.prism-string, |
| 142 | + .style &.prism-string { |
123 | 143 | color: #fcfcff;
|
124 | 144 | background: none;
|
125 | 145 | body.theme-light & {
|
126 | 146 | color: #373b4d;
|
127 | 147 | }
|
128 | 148 | }
|
129 | 149 |
|
130 |
| - &.atrule, |
131 |
| - &.attr-value, |
132 |
| - &.keyword { |
| 150 | + &.prism-atrule, |
| 151 | + &.prism-attr-value, |
| 152 | + &.prism-keyword { |
133 | 153 | color: #cbb1fc;
|
134 | 154 | body.theme-light & {
|
135 | 155 | color: #6a6af7;
|
136 | 156 | }
|
137 | 157 | }
|
138 |
| - &.function { |
| 158 | + &.prism-function { |
139 | 159 | color: #ffa1ce;
|
140 | 160 | body.theme-light & {
|
141 | 161 | color: #f02e7f;
|
142 | 162 | }
|
143 | 163 | }
|
144 |
| - &.class-name { |
| 164 | + &.prism-class-name { |
145 | 165 | color: #a1c4ff;
|
146 | 166 | body.theme-light & {
|
147 | 167 | color: #62aed2;
|
148 | 168 | }
|
149 | 169 | }
|
150 |
| - &.regex, |
151 |
| - &.important, |
152 |
| - &.variable { |
| 170 | + &.prism-regex, |
| 171 | + &.prism-important, |
| 172 | + &.prism-variable { |
153 | 173 | color: #a1c4ff;
|
154 | 174 | body.theme-light & {
|
155 | 175 | color: #62aed2;
|
|
0 commit comments