diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index 8b939d183e..53c268a27a 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -2,7 +2,11 @@ title: Component format --- -Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML: +--- + +Components are the building blocks of Svelte applications. They are written into `.svelte` files, using a superset of HTML. + +All three sections — script, styles and markup — are optional. ```html ``` - #### 2. Assignments are 'reactive' -To change component state and trigger a re-render, just assign to a locally declared variable: +--- + +To change component state and trigger a re-render, just assign to a locally declared variable. + +Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect. ```html ``` -Update expressions (`count += 1`) and property assignments (`obj.x = y`) have the same effect. - - #### 3. `$:` marks a statement as reactive +--- + Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the `$:` label. Reactive statements run immediately before the component updates, whenever the values that they depend on have changed: ```html @@ -84,6 +89,8 @@ Any top-level statement (i.e. not inside a block or a function) can be made reac ``` +--- + If a statement consists entirely of an assignment to an undeclared variable, Svelte will inject a `let` declaration on your behalf: ```html @@ -94,10 +101,13 @@ If a statement consists entirely of an assignment to an undeclared variable, Sve ``` - #### 4. Prefix stores with `$` to access their values -Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, and set up a store subscription that will be unsubscribed when appropriate: +--- + +Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, and set up a store subscription that will be unsubscribed when appropriate. + +Local variables (that do not represent store values) must *not* have a `$` prefix. ```html ``` -Local variables (that do not represent store values) must *not* have a `$` prefix. - #### Module context diff --git a/site/src/routes/docs/_sections.js b/site/src/routes/docs/_sections.js index 32137c0122..5fb7a61256 100644 --- a/site/src/routes/docs/_sections.js +++ b/site/src/routes/docs/_sections.js @@ -48,6 +48,14 @@ export default function() { const renderer = new marked.Renderer(); + let block_open = false; + + renderer.hr = (...args) => { + block_open = true; + + return '
${highlighted}
${highlighted}