Skip to content

Commit ce1142d

Browse files
Document codeblock deep-linking feature
Add documentation for the new deep-linking feature in code blocks that allows defining a links map to make specific text clickable. Includes examples for exact string matching, regex pattern matching, and combining both approaches. Co-Authored-By: Catherine Deskur <[email protected]>
1 parent d3cc43e commit ce1142d

File tree

1 file changed

+103
-2
lines changed
  • fern/products/docs/pages/component-library/default-components

1 file changed

+103
-2
lines changed

fern/products/docs/pages/component-library/default-components/code-blocks.mdx

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,112 @@ To disable scrolling and wrap overflow onto the next line, use the `wordWrap` pr
303303
</Tabs>
304304

305305

306+
## Deep-linking
307+
308+
You can make specific text within code blocks clickable by defining a `links` map. This is useful for linking to documentation, API references, or related resources directly from your code examples.
309+
310+
The `links` property accepts a map where keys are matching patterns (exact strings or regex) and values are the URLs to link to.
311+
312+
### Exact string matching
313+
314+
<Tabs>
315+
<Tab title="Example">
316+
```typescript links={"PlantClient": "https://example.com/api/plant-client", "createPlant": "https://example.com/api/create-plant"}
317+
import { PlantClient } from "@plantstore/sdk";
318+
319+
const client = new PlantClient({ apiKey: "YOUR_API_KEY" });
320+
const plant = await client.createPlant({
321+
name: "Monstera",
322+
species: "Monstera deliciosa"
323+
});
324+
```
325+
</Tab>
326+
<Tab title="Markdown">
327+
````markdown
328+
```typescript links={"PlantClient": "https://example.com/api/plant-client", "createPlant": "https://example.com/api/create-plant"}
329+
import { PlantClient } from "@plantstore/sdk";
330+
331+
const client = new PlantClient({ apiKey: "YOUR_API_KEY" });
332+
const plant = await client.createPlant({
333+
name: "Monstera",
334+
species: "Monstera deliciosa"
335+
});
336+
```
337+
````
338+
339+
<Note>
340+
The `links` property uses JSON format. Each key in the map is matched exactly against text in the code block, and matching text becomes a clickable link to the corresponding URL.
341+
</Note>
342+
</Tab>
343+
</Tabs>
344+
345+
### Regex pattern matching
346+
347+
You can use regex patterns for more flexible matching. This is useful when you want to link multiple variations or patterns of text.
348+
349+
<Tabs>
350+
<Tab title="Example">
351+
```python links={"Plant\\w+": "https://example.com/api/plant-models", "create_\\w+": "https://example.com/api/create-methods"}
352+
from plantstore import PlantClient, PlantConfig
353+
354+
client = PlantClient(api_key="YOUR_API_KEY")
355+
plant = client.create_plant(
356+
name="Fiddle Leaf Fig",
357+
species="Ficus lyrata"
358+
)
359+
```
360+
</Tab>
361+
<Tab title="Markdown">
362+
````markdown
363+
```python links={"Plant\\w+": "https://example.com/api/plant-models", "create_\\w+": "https://example.com/api/create-methods"}
364+
from plantstore import PlantClient, PlantConfig
365+
366+
client = PlantClient(api_key="YOUR_API_KEY")
367+
plant = client.create_plant(
368+
name="Fiddle Leaf Fig",
369+
species="Ficus lyrata"
370+
)
371+
```
372+
````
373+
374+
<Note>
375+
When using regex patterns, remember to escape special characters with double backslashes (e.g., `\\w+`, `\\d+`) in the JSON string.
376+
</Note>
377+
</Tab>
378+
</Tabs>
379+
380+
### Combining exact and regex patterns
381+
382+
You can mix exact string matching and regex patterns in the same `links` map:
383+
384+
<Tabs>
385+
<Tab title="Example">
386+
```javascript links={"fetchPlants": "https://example.com/api/fetch", "Plant\\w+": "https://example.com/api/types"}
387+
async function fetchPlants() {
388+
const response = await fetch('/api/plants');
389+
const data: PlantResponse = await response.json();
390+
return data.plants;
391+
}
392+
```
393+
</Tab>
394+
<Tab title="Markdown">
395+
````markdown
396+
```javascript links={"fetchPlants": "https://example.com/api/fetch", "Plant\\w+": "https://example.com/api/types"}
397+
async function fetchPlants() {
398+
const response = await fetch('/api/plants');
399+
const data: PlantResponse = await response.json();
400+
return data.plants;
401+
}
402+
```
403+
````
404+
</Tab>
405+
</Tabs>
406+
306407
## Combining props
307408

308-
You can combine the `title`, `highlight`, `focus`, `startLine`, `maxLines`, and `wordWrap`
409+
You can combine the `title`, `highlight`, `focus`, `startLine`, `maxLines`, `wordWrap`, and `links`
309410
props to create a code block with a title, highlighted lines, specific starting line,
310-
and a maximum height.
411+
a maximum height, and clickable links.
311412

312413
<Tabs>
313414
<Tab title="Example">

0 commit comments

Comments
 (0)