Code
Syntax-highlighted code blocks via Prism, with light and dark theme support. The light and dark themes are configured through the prism.theme and prism.darkTheme settings in docusaurus.config.js, and the active theme follows the site's color mode automatically.
Inline Code
Use single backticks: const x = 42.
Code Blocks
Specify the language after the opening triple backticks. Wrap in <Code> for a numbered, captioned, cross-referenceable block:
import torch.nn as nn
class TransformerBlock(nn.Module):
def __init__(self, d_model, n_heads, d_ff):
super().__init__()
self.attn = nn.MultiheadAttention(d_model, n_heads)
self.ff = nn.Sequential(nn.Linear(d_model, d_ff), nn.GELU(), nn.Linear(d_ff, d_model))
self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)
def forward(self, x):
x = self.norm1(x + self.attn(x, x, x)[0])
x = self.norm2(x + self.ff(x))
return x
def train_step(model, batch, optimizer):
optimizer.zero_grad()
loss = model(batch)
loss.backward()
optimizer.step()
return loss.item()
The # highlight-next-line comment in Code 2 is a Docusaurus directive rather than an ordinary code comment, and it highlights the line that follows it. To highlight a span of lines, wrap them with # highlight-start and # highlight-end, or use the range syntax such as {2,4-6} after the language tag on the opening fence.
Reference them inline: see and .
Supported Languages
| Language | Tag | Example | Description |
|---|---|---|---|
| Python | python | def foo(): pass | ML, data science, scripting |
| JavaScript | js | const x = 42; | Frontend, Node.js, React |
| TypeScript | ts | let x: number = 42; | Typed JavaScript |
| Bash | bash | echo "hello" | Shell scripts, CLI commands |
| C / C++ | c / cpp | int main() {} | Systems, CUDA kernels |
| Java | java | System.out.println() | Enterprise, Android |
| Rust | rust | fn main() {} | Systems, performance-critical |
| YAML / JSON | yaml / json | key: value | Configuration files |
| LaTeX | latex | \frac{a}{b} | Math typesetting |
| SQL | sql | SELECT * FROM t | Database queries |
Only the languages bundled by prism-react-renderer are highlighted by default. Python, JavaScript, TypeScript, C, C++, Rust, SQL, YAML, and JSON are bundled and work out of the box. Bash, Java, and LaTeX are not bundled, so they render as plaintext until you add them to the additionalLanguages array in the Prism configuration of docusaurus.config.js.
Full list at Prism supported languages.
Algorithms
The <Algorithm> component renders a bordered pseudocode block with a numbered caption:
Input: learning rate , initial parameters , dataset
- for do
- Sample mini-batch
- end for
Output: trained parameters