Skip to content

Commit a8396a5

Browse files
ethanpalmdks333
andauthored
Docs updates for new Codeblock v3 docs (#802)
* outline for updates * update intro * add option syntax * update title section * icon section * line highlighting and focusing * showLineNumbers * expandable * wrap * copyedits * typo * update to lines * add nav tag * update md to mdx * support for all Shiki languages * update examples * edit `New` tag * group code block options * add more options to code block example * add links to icon libraries * fix heading --------- Co-authored-by: dks333 <[email protected]>
1 parent 40d2e2c commit a8396a5

File tree

1 file changed

+114
-120
lines changed

1 file changed

+114
-120
lines changed

code.mdx

Lines changed: 114 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22
title: "Code"
33
description: "Display inline code and code blocks"
44
icon: "code"
5+
tag: "New"
56
---
67

7-
## Basic
8+
## Adding code samples
89

9-
### Inline Code
10+
You can add inline code snippets or code blocks. Code blocks support meta options for syntax highlighting, titles, line highlighting, icons, and more.
11+
12+
### Inline code
1013

1114
To denote a `word` or `phrase` as code, enclose it in backticks (\`).
1215

1316
```mdx
1417
To denote a `word` or `phrase` as code, enclose it in backticks (`).
1518
```
1619

17-
### Code Block
20+
### Code blocks
1821

19-
Use [fenced code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) by enclosing code in three backticks and follow the leading ticks with the programming language of your snippet to get syntax highlighting. Optionally, you can also write the name of your code after the programming language.
22+
Use [fenced code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) by enclosing code in three backticks. Specify the programming language for syntax highlighting and to enable meta options. Add any meta options after the language.
2023

21-
```java HelloWorld.java
24+
```java HelloWorld.java lines icon="java"
2225
class HelloWorld {
2326
public static void main(String[] args) {
2427
System.out.println("Hello, World!");
@@ -27,7 +30,7 @@ class HelloWorld {
2730
```
2831

2932
````mdx
30-
```java HelloWorld.java
33+
```java HelloWorld.java lines icon="java"
3134
class HelloWorld {
3235
public static void main(String[] args) {
3336
System.out.println("Hello, World!");
@@ -36,9 +39,23 @@ class HelloWorld {
3639
```
3740
````
3841

39-
## Syntax Highlighting
42+
## Code block options
43+
44+
You can add meta options to your code blocks to customize their appearance.
45+
46+
<Note>
47+
You must specify a programming language for a code block before adding any other meta options.
48+
</Note>
49+
50+
### Option syntax
51+
52+
* **String and boolean options**: Wrap with `""`, `''`, or no quotes.
53+
* **Expression options**: Wrap with `{}`, `""`, or `''`.
4054

41-
Enable syntax highlighting by adding the language name after the opening backticks of a code snippet.
55+
### Syntax highlighting
56+
Enable syntax highlighting by specifying the programming language after the opening backticks of a code block.
57+
58+
We use Shiki for syntax highlighting and support all available languages. See the full list of [languages](https://shiki.style/languages) in Shiki's documentation.
4259

4360
```java
4461
class HelloWorld {
@@ -58,124 +75,36 @@ class HelloWorld {
5875
```
5976
````
6077

61-
### Languages
62-
63-
We use [Shiki](https://shiki.style/languages) for syntax highlighting and support these languages using standard markdown syntax:
64-
65-
<table className="border-collapse">
66-
<thead>
67-
<tr>
68-
<th className="pr-12 py-2 text-left font-medium">Language</th>
69-
<th className="pr-12 py-2 text-left font-medium">ID</th>
70-
</tr>
71-
</thead>
72-
<tbody>
73-
<tr>
74-
<td className="pr-12 py-2">Bash</td>
75-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">bash</code></td>
76-
</tr>
77-
<tr className="">
78-
<td className="pr-12 py-2">Laravel Blade</td>
79-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">blade</code></td>
80-
</tr>
81-
<tr>
82-
<td className="pr-12 py-2">C</td>
83-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">c</code></td>
84-
</tr>
85-
<tr className="">
86-
<td className="pr-12 py-2">C++</td>
87-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">c++</code></td>
88-
</tr>
89-
<tr>
90-
<td className="pr-12 py-2">C#</td>
91-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">c#</code></td>
92-
</tr>
93-
<tr className="">
94-
<td className="pr-12 py-2">Dart</td>
95-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">dart</code></td>
96-
</tr>
97-
<tr>
98-
<td className="pr-12 py-2">Go</td>
99-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">go</code></td>
100-
</tr>
101-
<tr className="">
102-
<td className="pr-12 py-2">Java</td>
103-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">java</code></td>
104-
</tr>
105-
<tr>
106-
<td className="pr-12 py-2">JavaScript</td>
107-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">javascript</code></td>
108-
</tr>
109-
<tr className="">
110-
<td className="pr-12 py-2">JSON</td>
111-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">json</code></td>
112-
</tr>
113-
<tr>
114-
<td className="pr-12 py-2">JSX</td>
115-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">jsx</code></td>
116-
</tr>
117-
<tr className="">
118-
<td className="pr-12 py-2">Kotlin</td>
119-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">kotlin</code></td>
120-
</tr>
121-
<tr>
122-
<td className="pr-12 py-2">Log</td>
123-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">log</code></td>
124-
</tr>
125-
<tr className="">
126-
<td className="pr-12 py-2">Markdown</td>
127-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">markdown</code></td>
128-
</tr>
129-
<tr>
130-
<td className="pr-12 py-2">PHP</td>
131-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">php</code></td>
132-
</tr>
133-
<tr className="">
134-
<td className="pr-12 py-2">Python</td>
135-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">python</code></td>
136-
</tr>
137-
<tr>
138-
<td className="pr-12 py-2">Ruby</td>
139-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">ruby</code></td>
140-
</tr>
141-
<tr className="">
142-
<td className="pr-12 py-2">Swift</td>
143-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">swift</code></td>
144-
</tr>
145-
<tr>
146-
<td className="pr-12 py-2">TypeScript</td>
147-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">typescript</code></td>
148-
</tr>
149-
<tr className="">
150-
<td className="pr-12 py-2">TSX</td>
151-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">tsx</code></td>
152-
</tr>
153-
<tr>
154-
<td className="pr-12 py-2">YAML</td>
155-
<td className="pr-12 py-2"><code className="px-1 rounded text-sm">yaml</code></td>
156-
</tr>
157-
</tbody>
158-
</table>
159-
160-
## Names
161-
162-
Add a title after the programming language to set the name of your code example. The text can be anything as long as its all in one line.
78+
### Title
79+
Add a title after the programming language to label your code example. Titles can be any string on a single line.
16380

16481
```javascript Code Block Example
16582
const hello = "world";
16683
```
16784

168-
````mdx Code Block Example
85+
````mdx
16986
```javascript Code Block Example
17087
const hello = "world";
17188
```
17289
````
17390

174-
## Line Highlighting
91+
### Icon
92+
Add an icon to your code block. You can use [FontAwesome](https://fontawesome.com/icons) icons, [Lucide](https://lucide.dev/icons/) icons, or absolute URLs.
17593

176-
Highlight specific lines in your code blocks by adding a special comment after the language identifier. Use curly braces `{}` and specify line numbers or ranges separated by commas.
94+
```javascript icon="square-js"
95+
const hello = "world";
96+
```
17797

178-
```javascript Line Highlighting Example {1,3-5}
98+
````mdx
99+
```javascript icon="square-js"
100+
const hello = "world";
101+
```
102+
````
103+
104+
### Line Highlighting
105+
Highlight specific lines in your code blocks using `highlight` with the line numbers or ranges you want to highlight.
106+
107+
```javascript Line Highlighting Example highlight={1-2,5}
179108
const greeting = "Hello, World!";
180109
function sayHello() {
181110
console.log(greeting);
@@ -184,7 +113,7 @@ sayHello();
184113
```
185114

186115
````mdx
187-
```javascript Line Highlighting Example {1,3-5}
116+
```javascript Line Highlighting Example highlight={1-2,5}
188117
const greeting = "Hello, World!";
189118
function sayHello() {
190119
console.log(greeting);
@@ -193,11 +122,52 @@ sayHello();
193122
```
194123
````
195124

196-
## Expandable
125+
### Line focusing
126+
Focus on specific lines in your code blocks using `focus` with line numbers or ranges.
127+
128+
```javascript Line Focus Example focus={2,4-5}
129+
const greeting = "Hello, World!";
130+
function sayHello() {
131+
console.log(greeting);
132+
}
133+
sayHello();
134+
```
135+
136+
````mdx
137+
```javascript Line Focus Example focus={2,4-5}
138+
const greeting = "Hello, World!";
139+
function sayHello() {
140+
console.log(greeting);
141+
}
142+
sayHello();
143+
```
144+
````
197145

198-
If you have a long code block and `[expandable]` after your title to make it close and expand.
146+
### Show line numbers
147+
Display line numbers on the left side of your code block using `lines`.
199148

200-
```python library.py [expandable]
149+
```javascript Show Line Numbers Example lines
150+
const greeting = "Hello, World!";
151+
function sayHello() {
152+
console.log(greeting);
153+
}
154+
sayHello();
155+
```
156+
157+
````mdx
158+
```javascript Show Line Numbers Example lines
159+
const greeting = "Hello, World!";
160+
function sayHello() {
161+
console.log(greeting);
162+
}
163+
sayHello();
164+
```
165+
````
166+
167+
### Expandable
168+
Allow users to expand and collapse long code blocks using `expandable`.
169+
170+
```python Expandable Example expandable
201171
from datetime import datetime, timedelta
202172
from typing import Dict, List, Optional
203173
from dataclasses import dataclass
@@ -288,8 +258,32 @@ if __name__ == "__main__":
288258
```
289259

290260
````mdx
291-
```javascript Expandable Example [expandable]
292-
const greeting = "Hello, World!";
261+
```python Expandable Example expandable
262+
from datetime import datetime, timedelta
263+
from typing import Dict, List, Optional
264+
from dataclasses import dataclass
265+
266+
# ...
267+
268+
if __name__ == "__main__":
269+
main()
270+
```
271+
````
272+
273+
### Wrap
274+
Enable text wrapping for long lines using `wrap`. This prevents horizontal scrolling and makes long lines easier to read.
275+
276+
```javascript Wrap Example wrap
277+
const greeting = "Hello, World! I am a long line of text that will wrap to the next line.";
278+
function sayHello() {
279+
console.log(greeting);
280+
}
281+
sayHello();
282+
```
283+
284+
````mdx
285+
```javascript Wrap Example wrap
286+
const greeting = "Hello, World! I am a long line of text that will wrap to the next line.";
293287
function sayHello() {
294288
console.log(greeting);
295289
}

0 commit comments

Comments
 (0)