Inline Code Snippets
Enclose code within single backticks ` to display short code elements inline with your text. This works perfectly for variable names, method calls, or quick code references.
The console.log() function outputs messages to the browser console.
Example markup:
The `console.log()` function outputs messages to the browser console.
Multi-line Code Blocks
Create code blocks using triple backticks ``` to showcase complete functions, algorithms, or substantial code examples. This format preserves indentation and code structure.
Basic Code Block
function greetUser(username) {
return `Welcome back, ${username}!`;
}
greetUser("Developer");
Example markup:
```
function greetUser(username) {
return `Welcome back, ${username}!`;
}
greetUser("Developer");
```
Language-Specific Highlighting
Add the programming language name after the opening triple backticks ``` to enable syntax highlighting. This dramatically improves code readability and helps distinguish different language elements.
Generic code block without language specification.
const message = "No syntax highlighting applied";
console.log(message);
Example markup:
```
Generic code block without language specification.
const message = "No syntax highlighting applied";
console.log(message);
```
// JavaScript code with proper syntax highlighting
class APIClient {
constructor(baseURL) {
this.baseURL = baseURL;
}
async fetchData(endpoint) {
const response = await fetch(`${this.baseURL}/${endpoint}`);
return response.json();
}
}
Example markup:
```javascript
// JavaScript code with proper syntax highlighting
class APIClient {
constructor(baseURL) {
this.baseURL = baseURL;
}
async fetchData(endpoint) {
const response = await fetch(`${this.baseURL}/${endpoint}`);
return response.json();
}
}
```
Filename Labels
Add filename information to provide context for your code examples:
```bash filename="deploy.sh"
#!/bin/bash
echo "Starting deployment process..."
npm run build
docker build -t myapp:latest .
kubectl apply -f deployment.yaml
echo "Deployment completed successfully"
```
will generate
#!/bin/bash
echo "Starting deployment process..."
npm run build
docker build -t myapp:latest .
kubectl apply -f deployment.yaml
echo "Deployment completed successfully"
Code Formatting Best Practices
Inline Code Usage
- Use inline code for technical terms, API endpoints, and configuration values
- Apply to file paths, command names, and short code snippets
- Avoid for long expressions that break text flow
Code Block Guidelines
- Always specify language for syntax highlighting when possible
- Include relevant comments to explain complex logic
- Maintain consistent indentation throughout examples
- Use realistic, contextual examples rather than generic placeholders