Skip to main content

Essentials

Code Blocks

Display code with syntax highlighting, titles, and line numbers.

Basic code blocks

Use triple backticks to create a code block with syntax highlighting:

def hello():
print("Hello, World!")

hello()

Code with titles

Add a title to your code block to show the filename:

app.js
const express = require('express');
const app = express();

app.get('/', (req, res) => {
res.send('Hello World');
});

app.listen(3000);

Line highlighting

Highlight specific lines to draw attention:

config.py
DATABASE = {
'engine': 'postgresql',
'host': 'localhost',
'port': 5432,
'name': 'myapp',
}

Multiple languages

JavaScript

async function fetchData(url) {
const response = await fetch(url);
const data = await response.json();
return data;
}

Python

import requests

def fetch_data(url):
response = requests.get(url)
return response.json()

Bash

#!/bin/bash
echo "Installing dependencies..."
npm install
echo "Starting server..."
npm start

YAML

services:
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html

JSON

{
"name": "my-project",
"version": "1.0.0",
"dependencies": {
"express": "^4.18.0",
"dotenv": "^16.0.0"
}
}

Inline code

Use single backticks for inline code within a sentence. For example, run npm install to install dependencies, then npm start to launch the server.