|
8 | 8 | </script> |
9 | 9 |
|
10 | 10 | <script lang="ts"> |
11 | | - import { Badge, Icon } from '@appwrite.io/pink-svelte'; |
12 | | - import { IconCode, IconAndroid, IconFlutter, IconApple } from '@appwrite.io/pink-icons-svelte'; |
13 | | - import Prism from 'prismjs'; |
14 | | - import 'prismjs/components/prism-dart'; |
15 | | - import 'prismjs/components/prism-kotlin'; |
16 | | - import 'prismjs/components/prism-json'; |
17 | | - import 'prismjs/components/prism-bash'; |
18 | | - import 'prismjs/components/prism-yaml'; |
19 | | - import 'prismjs/components/prism-swift'; |
20 | | - import 'prismjs/plugins/autoloader/prism-autoloader'; |
21 | | - import 'prismjs/plugins/custom-class/prism-custom-class'; |
22 | | - import 'prismjs/plugins/line-numbers/prism-line-numbers'; |
23 | 11 | import { Copy } from '.'; |
| 12 | + import { Badge, Icon, Code } from '@appwrite.io/pink-svelte'; |
| 13 | + import { IconCode, IconAndroid, IconFlutter, IconApple } from '@appwrite.io/pink-icons-svelte'; |
24 | 14 |
|
25 | 15 | let { |
26 | 16 | label = null, |
|
37 | 27 | label?: string; |
38 | 28 | labelIcon?: 'code' | 'android' | 'flutter' | 'apple'; |
39 | 29 | code: string; |
40 | | - language: 'js' | 'html' | 'dart' | 'kotlin' | 'json' | 'sh' | 'yml' | 'swift'; |
| 30 | + language: Language; |
41 | 31 | withLineNumbers?: boolean; |
42 | 32 | withCopy?: boolean; |
43 | 33 | noMargin?: boolean; |
|
60 | 50 | return null; |
61 | 51 | } |
62 | 52 | } |
63 | | -
|
64 | | - Prism.plugins.customClass.prefix('prism-'); |
65 | | -
|
66 | | - $effect(() => Prism.highlightAll()); |
67 | 53 | </script> |
68 | 54 |
|
69 | 55 | <section |
70 | 56 | class="box u-overflow-hidden {classes}" |
71 | 57 | class:common-section={!noMargin} |
72 | | - class:noBoxPadding> |
| 58 | + class:noBoxPadding |
| 59 | + class:with-scroll={allowScroll}> |
73 | 60 | <div |
74 | 61 | class="controls u-position-absolute u-inset-inline-end-8 u-inset-block-start-8 u-flex u-gap-8"> |
75 | 62 | {#if label} |
|
87 | 74 | </Copy> |
88 | 75 | {/if} |
89 | 76 | </div> |
90 | | - <pre |
91 | | - class:with-scroll={allowScroll} |
92 | | - class={`language-${language}`} |
93 | | - class:line-numbers={withLineNumbers}><code>{code}</code></pre> |
| 77 | + <Code {code} lang={language} lineNumbers={withLineNumbers} hideHeader /> |
94 | 78 | </section> |
95 | 79 |
|
96 | | -<!-- svelte-ignore css_unused_selector --> |
97 | | -<style lang="scss" global> |
98 | | - @import 'prismjs/themes/prism.css'; |
99 | | - @import 'prismjs/plugins/line-numbers/prism-line-numbers.css'; |
100 | | -
|
101 | | - .box { |
102 | | - --p-box-background-color: var(--color-neutral-400) !important; |
103 | | -
|
104 | | - body.theme-light & { |
105 | | - --p-box-background-color: var(--color-neutral-5) !important; |
106 | | - } |
107 | | -
|
108 | | - .controls { |
109 | | - z-index: 2; |
110 | | - } |
111 | | - } |
112 | | -
|
| 80 | +<style lang="scss"> |
113 | 81 | .noBoxPadding { |
114 | 82 | padding: 0 !important; |
115 | 83 | } |
116 | 84 |
|
117 | 85 | .with-scroll { |
118 | 86 | height: 100%; |
119 | | - overflow: auto; |
120 | | - } |
121 | | -
|
122 | | - code, |
123 | | - pre { |
124 | | - &[class*='language-'] { |
125 | | - color: #fcfcff; |
126 | | - text-shadow: none; |
127 | | - font-family: 'Source Code Pro'; |
128 | | -
|
129 | | - &.line-numbers { |
130 | | - padding-left: 2.5em; |
131 | | - } |
132 | | - body.theme-light & { |
133 | | - color: #373b4d; |
134 | | - } |
135 | | - } |
136 | | - ::selection, |
137 | | - &::selection { |
138 | | - text-shadow: none; |
139 | | - background: #b3d4fc; |
140 | | - } |
141 | | -
|
142 | | - &.line-numbers .line-numbers-rows { |
143 | | - border: none; |
144 | | -
|
145 | | - > span::before { |
146 | | - color: #868ea3; |
147 | | - } |
148 | | - } |
149 | | - } |
150 | | -
|
151 | | - :not(pre) > code[class*='language-'], |
152 | | - pre[class*='language-'] { |
153 | | - background: hsl(var(--p-box-background-color)); |
154 | | -
|
155 | | - margin: 0; |
156 | | - } |
157 | | - .prism-token { |
158 | | - &.prism-comment, |
159 | | - &.prism-prolog, |
160 | | - &.prism-doctype, |
161 | | - &.prism-cdata { |
162 | | - color: #868ea3; |
163 | | - } |
164 | | -
|
165 | | - &.prism-punctuation { |
166 | | - color: #fcfcff; |
167 | | -
|
168 | | - body.theme-light & { |
169 | | - color: #373b4d; |
170 | | - } |
171 | | - } |
172 | | - &.prism-property, |
173 | | - &.prism-tag, |
174 | | - &.prism-boolean, |
175 | | - &.prism-number, |
176 | | - &.prism-constant, |
177 | | - &.prism-symbol, |
178 | | - &.prism-deleted, |
179 | | - &.prism-selector, |
180 | | - &.prism-attr-name, |
181 | | - &.prism-string, |
182 | | - &.prism-char, |
183 | | - &.prism-builtin, |
184 | | - &.prism-inserted { |
185 | | - color: #fdc584; |
186 | | - body.theme-light & { |
187 | | - color: #e49545; |
188 | | - } |
189 | | - } |
190 | | - &.prism-operator, |
191 | | - &.prism-entity, |
192 | | - &.prism-url, |
193 | | - .language-css &.prism-string, |
194 | | - .style &.prism-string { |
195 | | - color: #fcfcff; |
196 | | - background: none; |
197 | | - body.theme-light & { |
198 | | - color: #373b4d; |
199 | | - } |
200 | | - } |
201 | | -
|
202 | | - &.prism-atrule, |
203 | | - &.prism-attr-value, |
204 | | - &.prism-keyword { |
205 | | - color: #cbb1fc; |
206 | | - body.theme-light & { |
207 | | - color: #6a6af7; |
208 | | - } |
209 | | - } |
210 | | - &.prism-function { |
211 | | - color: #ffa1ce; |
212 | | - body.theme-light & { |
213 | | - color: #f02e7f; |
214 | | - } |
215 | | - } |
216 | | - &.prism-class-name { |
217 | | - color: #a1c4ff; |
218 | | - body.theme-light & { |
219 | | - color: #62aed2; |
220 | | - } |
221 | | - } |
222 | | - &.prism-important, |
223 | | - &.prism-variable { |
224 | | - color: #a1c4ff; |
225 | | - body.theme-light & { |
226 | | - color: #62aed2; |
227 | | - } |
228 | | - } |
229 | | - &.prism-regex { |
230 | | - color: #a1c4ff; |
231 | | - body.theme-light & { |
232 | | - color: #62aed2; |
233 | | - } |
234 | | - } |
| 87 | + overflow: auto !important; |
235 | 88 | } |
236 | 89 | </style> |
0 commit comments