Skip to content

Commit 291d9fa

Browse files
committed
Annotation docs
1 parent eaa0b0b commit 291d9fa

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,9 @@ The regular expressions also support flags The two most common are `g` for globa
217217
You can also use [capturing groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Capturing_group) (see [fold example](/docs/code/fold)):
218218

219219
<Demo name="annotations/groups" />
220+
221+
## Using start/end comments instead of ranges
222+
223+
Instead of counting lines for the range, you can use `!name(start)` and `!name(end)` comments to mark the block:
224+
225+
<Demo name="annotations/start-end" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```js
2+
const lorem = ipsum == null ? 0 : 1
3+
// !border(start)
4+
dolor = lorem - sit(dolor)
5+
let amet = lorem ? consectetur(ipsum) : 3
6+
const elit = amet + dolor
7+
// !border(end)
8+
sed = elit * 2
9+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Content from "./content.md"
2+
import { RawCode, Pre, highlight } from "codehike/code"
3+
import { AnnotationHandler } from "codehike/code"
4+
5+
export default function Page() {
6+
return <Content components={{ Code }} />
7+
}
8+
9+
export async function Code({ codeblock }: { codeblock: RawCode }) {
10+
const highlighted = await highlight(codeblock, "github-dark")
11+
return (
12+
<Pre
13+
className="m-0 bg-zinc-950"
14+
code={highlighted}
15+
handlers={[borderHandler]}
16+
/>
17+
)
18+
}
19+
const borderHandler: AnnotationHandler = {
20+
name: "border",
21+
Block: ({ annotation, children }) => (
22+
<div style={{ border: "1px solid red" }}>{children}</div>
23+
),
24+
}

0 commit comments

Comments
 (0)