Skip to content

Commit 1d9a6d8

Browse files
committed
Document start end annotation comments
1 parent b4d10f5 commit 1d9a6d8

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

apps/web/content/docs/code/focus.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Focus blocks of code. Dim the unfocused code. Ensure the focused code is visible
1010

1111
Useful when you want to change a codeblock focus depending on the user's interaction.
1212

13+
The demo below uses `!focus(start)` and `!focus(end)` comments to define the focused range.
14+
1315
<Demo name="focus" />
1416

1517
## !implementation

apps/web/content/docs/concepts/annotations.mdx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,28 @@ We can use the `name` of those handlers as comments in the code to use the compo
4040

4141
## Annotation Comments
4242

43-
We use comments to annotate codeblocks. **The comment syntax depends on the language**. For example, in javascript we use `// !name(1:5)` but in python we use `# !name(1:5)`. For JSON (that doesn't support comments), the recommendation is to instead use `jsonc` or `json5`, which support comments.
43+
We use comments to annotate codeblocks. **The comment syntax depends on the language**. For example, in javascript we use `// !name(1:5)` or `// !name(start)`, but in python we use `# !name(1:5)` or `# !name(start)`. For JSON (that doesn't support comments), the recommendation is to instead use `jsonc` or `json5`, which support comments.
4444

4545
In the previous example we can see the two types of annotations:
4646

47-
- **Block annotations** are applied to a block of lines. They use parenthesis `()` to define the range of lines. The numbers are relative to the line where the comment is placed.
47+
- **Block annotations** are applied to a block of lines. They can use parenthesis `()` to define the range of lines, or `!name(start)` / `!name(end)` comments to mark the beginning and end of the block. Numeric ranges are relative to the line where the comment is placed.
4848
- **Inline annotations** are applied to a group of tokens inside a line. They use square brackets `[]` to define the range of columns included in the annotation.
4949

50+
For example, these two block annotations are equivalent:
51+
52+
```js
53+
// !focus(1:2)
54+
const b = 2
55+
const c = 3
56+
```
57+
58+
```js
59+
// !focus(start)
60+
const b = 2
61+
const c = 3
62+
// !focus(end)
63+
```
64+
5065
## Annotation Query
5166

5267
Any extra content in the annotation comment is passed to the annotation components as `query`.

apps/web/demos/focus/content.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ function ipsum(ipsum, dolor = 1) {
99
return dolor
1010
}
1111

12-
// !focus(1:5)
12+
// !focus(start)
1313
function dolor(ipsum, dolor = 1) {
1414
const sit = ipsum == null ? 0 : ipsum.sit
1515
dolor = sit - amet(dolor)
1616
return sit ? consectetur(ipsum) : []
1717
}
18+
// !focus(end)
1819
```

0 commit comments

Comments
 (0)