Skip to content

Commit d30e5a0

Browse files
Rich-HarrisRich Harris
andauthored
Add /// file annotations (sveltejs#285)
* add clickable file annotations to code blocks * add more file annotations * add no-file * toggle mobile view when clicking annotations * create files from annotations * make all inline file annotations interactive * dont exempt exercises with only one file, its weird --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 1bf38b7 commit d30e5a0

File tree

116 files changed

+448
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+448
-161
lines changed

content/tutorial/01-svelte/01-introduction/02-your-first-component/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A component that just renders some static markup isn't very interesting. Let's a
1111
First, add a script tag to your component and declare a `name` variable:
1212

1313
```svelte
14+
/// file: App.svelte
1415
+++<script>
1516
let name = 'Svelte';
1617
</script>+++
@@ -21,11 +22,13 @@ First, add a script tag to your component and declare a `name` variable:
2122
Then, we can refer to `name` in the markup:
2223

2324
```svelte
25+
/// file: App.svelte
2426
<h1>Hello +++{name}+++!</h1>
2527
```
2628

2729
Inside the curly braces, we can put any JavaScript we want. Try changing `name` to `name.toUpperCase()` for a shoutier greeting.
2830

2931
```svelte
32+
/// file: App.svelte
3033
<h1>Hello {name+++.toUpperCase()+++}!</h1>
3134
```

content/tutorial/01-svelte/01-introduction/03-dynamic-attributes/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Just like you can use curly braces to control text, you can use them to control
77
Our image is missing a `src` — let's add one:
88

99
```svelte
10+
/// file: App.svelte
1011
<img +++src={src}+++ />
1112
```
1213

@@ -19,6 +20,7 @@ When building web apps, it's important to make sure that they're _accessible_ to
1920
In this case, we're missing the `alt` attribute that describes the image for people using screenreaders, or people with slow or flaky internet connections that can't download the image. Let's add one:
2021

2122
```svelte
23+
/// file: App.svelte
2224
<img src={src} +++alt="A man dances."+++ />
2325
```
2426

@@ -29,5 +31,6 @@ We can use curly braces _inside_ attributes. Try changing it to `"{name} dances.
2931
It's not uncommon to have an attribute where the name and value are the same, like `src={src}`. Svelte gives us a convenient shorthand for these cases:
3032

3133
```svelte
34+
/// file: App.svelte
3235
<img +++{src}+++ alt="A man dances." />
3336
```

content/tutorial/01-svelte/01-introduction/04-styling/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Styling
55
Just like in HTML, you can add a `<style>` tag to your component. Let's add some styles to the `<p>` element:
66

77
```svelte
8+
/// file: App.svelte
89
<p>This is a paragraph.</p>
910
1011
<style>

content/tutorial/01-svelte/01-introduction/05-nested-components/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ It would be impractical to put your entire app in a single component. Instead, w
77
Add a `<script>` tag that imports `Nested.svelte`...
88

99
```svelte
10+
/// file: App.svelte
1011
+++<script>
1112
import Nested from './Nested.svelte';
1213
</script>+++
@@ -15,6 +16,7 @@ Add a `<script>` tag that imports `Nested.svelte`...
1516
...and include a `<Nested />` component:
1617

1718
```svelte
19+
/// file: App.svelte
1820
<p>This is a paragraph.</p>
1921
+++<Nested />+++
2022
```

content/tutorial/01-svelte/02-reactivity/01-reactive-assignments/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ At the heart of Svelte is a powerful system of _reactivity_ for keeping the DOM
77
To demonstrate it, we first need to wire up an event handler (we'll learn more about these [later](/tutorial/dom-events)):
88

99
```svelte
10+
/// file: App.svelte
1011
<button +++on:click={increment}+++>
1112
```
1213

1314
Inside the `increment` function, all we need to do is change the value of `count`:
1415

1516
```js
17+
/// file: App.svelte
1618
function increment() {
1719
+++count += 1;+++
1820
}

content/tutorial/01-svelte/02-reactivity/02-reactive-declarations/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Svelte automatically updates the DOM when your component's state changes. Often,
77
For these, we have _reactive declarations_. They look like this:
88

99
```js
10+
/// file: App.svelte
1011
let count = 0;
1112
+++$: doubled = count * 2;+++
1213
```
@@ -16,6 +17,7 @@ let count = 0;
1617
Let's use `doubled` in our markup:
1718

1819
```svelte
20+
/// file: App.svelte
1921
<button>...</button>
2022
2123
+++<p>{count} doubled is {doubled}</p>+++

content/tutorial/01-svelte/02-reactivity/03-reactive-statements/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Statements
55
We're not limited to declaring reactive _values_ — we can also run arbitrary _statements_ reactively. For example, we can log the value of `count` whenever it changes:
66

77
```js
8+
/// file: App.svelte
89
let count = 0;
910

1011
+++$: console.log(`the count is ${count}`);+++
@@ -13,6 +14,7 @@ let count = 0;
1314
You can easily group statements together with a block:
1415

1516
```js
17+
/// file: App.svelte
1618
$: +++{+++
1719
console.log(`the count is ${count}`);
1820
alert(`I SAID THE COUNT IS ${count}`);
@@ -22,6 +24,7 @@ $: +++{+++
2224
You can even put the `$:` in front of things like `if` blocks:
2325

2426
```js
27+
/// file: App.svelte
2528
$: +++if (count >= 10)+++ {
2629
alert('count is dangerously high!');
2730
count = 0;

content/tutorial/01-svelte/02-reactivity/04-updating-arrays-and-objects/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Because Svelte's reactivity is triggered by assignments, using array methods lik
77
One way to fix that is to add an assignment that would otherwise be redundant:
88

99
```js
10+
/// file: App.svelte
1011
function addNumber() {
1112
numbers.push(numbers.length + 1);
1213
+++numbers = numbers;+++
@@ -16,6 +17,7 @@ function addNumber() {
1617
But there's a more idiomatic solution:
1718

1819
```js
20+
/// file: App.svelte
1921
function addNumber() {
2022
numbers = +++[...numbers, numbers.length + 1];+++
2123
}
@@ -26,6 +28,7 @@ You can use similar patterns to replace `pop`, `shift`, `unshift` and `splice`.
2628
Assignments to _properties_ of arrays and objects — e.g. `obj.foo += 1` or `array[i] = x` — work the same way as assignments to the values themselves.
2729

2830
```js
31+
/// file: App.svelte
2932
function addNumber() {
3033
numbers[numbers.length] = numbers.length + 1;
3134
}
@@ -34,6 +37,7 @@ function addNumber() {
3437
A simple rule of thumb: the name of the updated variable must appear on the left hand side of the assignment. For example this...
3538

3639
```js
40+
/// no-file
3741
const foo = obj.foo;
3842
foo.bar = 'baz';
3943
```

content/tutorial/01-svelte/03-props/01-declaring-props/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ So far, we've dealt exclusively with internal state — that is to say, the valu
77
In any real application, you'll need to pass data from one component down to its children. To do that, we need to declare _properties_, generally shortened to 'props'. In Svelte, we do that with the `export` keyword. Edit the `Nested.svelte` component:
88

99
```svelte
10+
/// file: Nested.svelte
1011
<script>
1112
+++export+++ let answer;
1213
</script>

content/tutorial/01-svelte/03-props/02-default-values/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: Default values
55
We can easily specify default values for props in `Nested.svelte`:
66

77
```svelte
8+
/// file: Nested.svelte
89
<script>
910
export let answer +++= 'a mystery'+++;
1011
</script>
@@ -13,6 +14,7 @@ We can easily specify default values for props in `Nested.svelte`:
1314
If we now add a second component _without_ an `answer` prop, it will fall back to the default:
1415

1516
```svelte
17+
/// file: App.svelte
1618
<Nested answer={42}/>
1719
+++<Nested />+++
1820
```

0 commit comments

Comments
 (0)