Code
Syntax-highlighted code blocks via Prism, with light and dark theme support.
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()
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 |
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