Skip to content

feat: Copy code button #8995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions documentation/docs/02-template-syntax/03-logic-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ title: Logic blocks
## {#if ...}

```svelte
<!--- copy: false --->
{#if expression}...{/if}
```

```svelte
<!--- copy: false --->
{#if expression}...{:else if expression}...{/if}
```

```svelte
<!--- copy: false --->
{#if expression}...{:else}...{/if}
```

Expand Down Expand Up @@ -41,22 +44,27 @@ Additional conditions can be added with `{:else if expression}`, optionally endi
## {#each ...}

```svelte
<!--- copy: false --->
{#each expression as name}...{/each}
```

```svelte
<!--- copy: false --->
{#each expression as name, index}...{/each}
```

```svelte
<!--- copy: false --->
{#each expression as name (key)}...{/each}
```

```svelte
<!--- copy: false --->
{#each expression as name, index (key)}...{/each}
```

```svelte
<!--- copy: false --->
{#each expression as name}...{:else}...{/each}
```

Expand Down Expand Up @@ -125,18 +133,22 @@ Since Svelte 4 it is possible to iterate over iterables like `Map` or `Set`. Ite
## {#await ...}

```svelte
<!--- copy: false --->
{#await expression}...{:then name}...{:catch name}...{/await}
```

```svelte
<!--- copy: false --->
{#await expression}...{:then name}...{/await}
```

```svelte
<!--- copy: false --->
{#await expression then name}...{/await}
```

```svelte
<!--- copy: false --->
{#await expression catch name}...{/await}
```

Expand Down Expand Up @@ -186,6 +198,7 @@ Similarly, if you only want to show the error state, you can omit the `then` blo
## {#key ...}

```svelte
<!--- copy: false --->
{#key expression}...{/key}
```

Expand Down
4 changes: 4 additions & 0 deletions documentation/docs/02-template-syntax/04-special-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ title: Special tags
## {@html ...}

```svelte
<!--- copy: false --->
{@html expression}
```

Expand All @@ -24,10 +25,12 @@ The expression should be valid standalone HTML — `{@html "<div>"}content{@html
## {@debug ...}

```svelte
<!--- copy: false --->
{@debug}
```

```svelte
<!--- copy: false --->
{@debug var1, var2, ..., varN}
```

Expand Down Expand Up @@ -65,6 +68,7 @@ The `{@debug}` tag without any arguments will insert a `debugger` statement that
## {@const ...}

```svelte
<!--- copy: false --->
{@const assignment}
```

Expand Down
43 changes: 35 additions & 8 deletions documentation/docs/02-template-syntax/05-element-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ As well as attributes, elements can have _directives_, which control the element
## on:_eventname_

```svelte
<!--- copy: false --->
on:eventname={handler}
```

```svelte
<!--- copy: false --->
on:eventname|modifiers={handler}
```

Expand Down Expand Up @@ -72,7 +74,6 @@ If the `on:` directive is used without a value, the component will _forward_ the
It's possible to have multiple event listeners for the same event:

```svelte
<!--- file: App.svelte --->
<script>
let counter = 0;
function increment() {
Expand All @@ -91,6 +92,7 @@ It's possible to have multiple event listeners for the same event:
## bind:_property_

```svelte
<!--- copy: false --->
bind:property={variable}
```

Expand Down Expand Up @@ -186,6 +188,8 @@ Elements with the `contenteditable` attribute support the following bindings:

There are slight differences between each of these, read more about them [here](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#Differences_from_innerText).

<!-- for some reason puts the comment and html on same line -->
<!-- prettier-ignore -->
```svelte
<div contenteditable="true" bind:innerHTML={html} />
```
Expand Down Expand Up @@ -273,13 +277,13 @@ Block-level elements have 4 read-only bindings, measured using a technique simil
## bind:group

```svelte
<!--- copy: false --->
bind:group={variable}
```

Inputs that work together can use `bind:group`.

```svelte
<!--- file: App.svelte --->
<script>
let tortilla = 'Plain';

Expand All @@ -304,13 +308,13 @@ Inputs that work together can use `bind:group`.
## bind:this

```svelte
<!--- copy: false --->
bind:this={dom_node}
```

To get a reference to a DOM node, use `bind:this`.

```svelte
<!--- file: App.svelte --->
<script>
import { onMount } from 'svelte';

Expand All @@ -329,10 +333,12 @@ To get a reference to a DOM node, use `bind:this`.
## class:_name_

```svelte
<!--- copy: false --->
class:name={value}
```

```svelte
<!--- copy: false --->
class:name
```

Expand Down Expand Up @@ -393,14 +399,17 @@ When `style:` directives are combined with `style` attributes, the directives wi
## use:_action_

```svelte
<!--- copy: false --->
use:action
```

```svelte
<!--- copy: false --->
use:action={parameters}
```

```ts
/// copy: false
// @noErrors
action = (node: HTMLElement, parameters: any) => {
update?: (parameters: any) => void,
Expand All @@ -411,7 +420,6 @@ action = (node: HTMLElement, parameters: any) => {
Actions are functions that are called when an element is created. They can return an object with a `destroy` method that is called after the element is unmounted:

```svelte
<!--- file: App.svelte --->
<script>
/** @type {import('svelte/action').Action} */
function foo(node) {
Expand All @@ -433,7 +441,6 @@ An action can have a parameter. If the returned value has an `update` method, it
> Don't worry about the fact that we're redeclaring the `foo` function for every component instance — Svelte will hoist any functions that don't depend on local state out of the component definition.

```svelte
<!--- file: App.svelte --->
<script>
export let bar;

Expand Down Expand Up @@ -461,30 +468,37 @@ Read more in the [`svelte/action`](/docs/svelte-action) page.
## transition:_fn_

```svelte
<!--- copy: false --->
transition:fn
```

```svelte
<!--- copy: false --->
transition:fn={params}
```

```svelte
<!--- copy: false --->
transition:fn|global
```

```svelte
<!--- copy: false --->
transition:fn|global={params}
```

```svelte
<!--- copy: false --->
transition:fn|local
```

```svelte
<!--- copy: false --->
transition:fn|local={params}
```

```js
/// copy: false
// @noErrors
transition = (node: HTMLElement, params: any, options: { direction: 'in' | 'out' | 'both' }) => {
delay?: number,
Expand Down Expand Up @@ -544,7 +558,6 @@ The `t` argument passed to `css` is a value between `0` and `1` after the `easin
The function is called repeatedly _before_ the transition begins, with different `t` and `u` arguments.

```svelte
<!--- file: App.svelte --->
<script>
import { elasticOut } from 'svelte/easing';

Expand Down Expand Up @@ -644,50 +657,62 @@ An element with transitions will dispatch the following events in addition to an
## in:_fn_/out:_fn_

```svelte
<!--- copy: false --->
in:fn
```

```svelte
<!--- copy: false --->
in:fn={params}
```

```svelte
<!--- copy: false --->
in:fn|global
```

```svelte
<!--- copy: false --->
in:fn|global={params}
```

```svelte
<!--- copy: false --->
in:fn|local
```

```svelte
<!--- copy: false --->
in:fn|local={params}
```

```svelte
<!--- copy: false --->
out:fn
```

```svelte
<!--- copy: false --->
out:fn={params}
```

```svelte
<!--- copy: false --->
out:fn|global
```

```svelte
<!--- copy: false --->
out:fn|global={params}
```

```svelte
<!--- copy: false --->
out:fn|local
```

```svelte
<!--- copy: false --->
out:fn|local={params}
```

Expand All @@ -704,14 +729,17 @@ Unlike with `transition:`, transitions applied with `in:` and `out:` are not bid
## animate:_fn_

```svelte
<!--- copy: false --->
animate:name
```

```svelte
<!--- copy: false --->
animate:name={params}
```

```js
/// copy: false
// @noErrors
animation = (node: HTMLElement, { from: DOMRect, to: DOMRect } , params: any) => {
delay?: number,
Expand All @@ -723,6 +751,7 @@ animation = (node: HTMLElement, { from: DOMRect, to: DOMRect } , params: any) =>
```

```ts
/// copy: false
// @noErrors
DOMRect {
bottom: number,
Expand Down Expand Up @@ -772,7 +801,6 @@ The function is called repeatedly _before_ the animation begins, with different
<!-- TODO: Types -->

```svelte
<!--- file: App.svelte --->
<script>
import { cubicOut } from 'svelte/easing';

Expand Down Expand Up @@ -806,7 +834,6 @@ A custom animation function can also return a `tick` function, which is called _
> If it's possible to use `css` instead of `tick`, do so — CSS animations can run off the main thread, preventing jank on slower devices.

```svelte
<!--- file: App.svelte --->
<script>
import { cubicOut } from 'svelte/easing';

Expand Down
Loading