Skip to content

Commit d5e9559

Browse files
authored
feat(site): add svelte syntax highlighting (#4851)
1 parent f7d1bf3 commit d5e9559

File tree

6 files changed

+115
-108
lines changed

6 files changed

+115
-108
lines changed

site/content/docs/01-component-format.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Components are the building blocks of Svelte applications. They are written into
88

99
All three sections — script, styles and markup — are optional.
1010

11-
```html
11+
```sv
1212
<script>
1313
// logic goes here
1414
</script>
@@ -30,7 +30,7 @@ A `<script>` block contains JavaScript that runs when a component instance is cr
3030

3131
Svelte uses the `export` keyword to mark a variable declaration as a *property* or *prop*, which means it becomes accessible to consumers of the component (see the section on [attributes and props](docs#Attributes_and_props) for more information).
3232

33-
```html
33+
```sv
3434
<script>
3535
export let foo;
3636
@@ -46,7 +46,7 @@ You can specify a default initial value for a prop. It will be used if the compo
4646

4747
In development mode (see the [compiler options](docs#svelte_compile)), a warning will be printed if no default initial value is provided and the consumer does not specify a value. To squelch this warning, ensure that a default initial value is specified, even if it is `undefined`.
4848

49-
```html
49+
```sv
5050
<script>
5151
export let bar = 'optional default initial value';
5252
export let baz = undefined;
@@ -57,7 +57,7 @@ In development mode (see the [compiler options](docs#svelte_compile)), a warning
5757

5858
If you export a `const`, `class` or `function`, it is readonly from outside the component. Function *expressions* are valid props, however.
5959

60-
```html
60+
```sv
6161
<script>
6262
// these are readonly
6363
export const thisIs = 'readonly';
@@ -75,7 +75,7 @@ If you export a `const`, `class` or `function`, it is readonly from outside the
7575

7676
You can use reserved words as prop names.
7777

78-
```html
78+
```sv
7979
<script>
8080
let className;
8181
@@ -95,7 +95,7 @@ Update expressions (`count += 1`) and property assignments (`obj.x = y`) have th
9595

9696
Because Svelte's reactivity is based on assignments, using array methods like `.push()` and `.splice()` won't automatically trigger updates. Options for getting around this can be found in the [tutorial](tutorial/updating-arrays-and-objects).
9797

98-
```html
98+
```sv
9999
<script>
100100
let count = 0;
101101
@@ -113,7 +113,7 @@ Because Svelte's reactivity is based on assignments, using array methods like `.
113113

114114
Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the `$:` [JS label syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label). Reactive statements run immediately before the component updates, whenever the values that they depend on have changed.
115115

116-
```html
116+
```sv
117117
<script>
118118
export let title;
119119
@@ -132,7 +132,7 @@ Any top-level statement (i.e. not inside a block or a function) can be made reac
132132

133133
If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf.
134134

135-
```html
135+
```sv
136136
<script>
137137
export let num;
138138
@@ -157,7 +157,7 @@ Note that the store must be declared at the top level of the component — not i
157157

158158
Local variables (that do not represent store values) must *not* have a `$` prefix.
159159

160-
```html
160+
```sv
161161
<script>
162162
import { writable } from 'svelte/store';
163163
@@ -199,7 +199,7 @@ You cannot `export default`, since the default export is the component itself.
199199

200200
> Variables defined in `module` scripts are not reactive — reassigning them will not trigger a rerender even though the variable itself will update. For values shared between multiple components, consider using a [store](docs#svelte_store).
201201
202-
```html
202+
```sv
203203
<script context="module">
204204
let totalComponents = 0;
205205
@@ -225,7 +225,7 @@ CSS inside a `<style>` block will be scoped to that component.
225225

226226
This works by adding a class to affected elements, which is based on a hash of the component styles (e.g. `svelte-123xyz`).
227227

228-
```html
228+
```sv
229229
<style>
230230
p {
231231
/* this will only affect <p> elements in this component */
@@ -238,7 +238,7 @@ This works by adding a class to affected elements, which is based on a hash of t
238238

239239
To apply styles to a selector globally, use the `:global(...)` modifier.
240240

241-
```html
241+
```sv
242242
<style>
243243
:global(body) {
244244
/* this will apply to <body> */

0 commit comments

Comments
 (0)