Code Block Demo
This page demonstrates how to use code blocks in your Markdown content.
Basic Usage - Code Blocks
Regular code blocks work with triple backticks:
// Regular markdown code block
function helloWorld() {
console.log("Hello, world!");
}
JavaScript Example
// JavaScript example
function helloWorld() {
console.log("Hello, world!");
return true;
}
const result = helloWorld();
CSS Example
/* CSS example */
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.button {
padding: 0.5rem 1rem;
background-color: #6272a4;
color: white;
border-radius: 4px;
}
TypeScript Example
// TypeScript interface and implementation
interface User {
id: number;
name: string;
email: string;
isActive: boolean;
}
class UserService {
private users: User[] = [];
constructor() {
console.log("User service initialized");
}
addUser(user: User): void {
this.users.push(user);
}
getUserById(id: number): User | undefined {
return this.users.find(user => user.id === id);
}
getAllActiveUsers(): User[] {
return this.users.filter(user => user.isActive);
}
}
// Usage
const service = new UserService();
service.addUser({
id: 1,
name: "John Doe",
email: "john@example.com",
isActive: true
});
HTML Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Welcome to our site</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section class="hero">
<h2>Main content area</h2>
<p>This is where the primary content goes.</p>
</section>
</main>
<footer>
<p>© 2023 Example Company</p>
</footer>
</body>
</html>
Supported Languages
Astro’s built-in syntax highlighting supports all common languages including:
- JavaScript/TypeScript
- HTML/CSS/SCSS
- Python
- Java
- C/C++/C#
- Go
- Rust
- Ruby
- PHP
- Shell/Bash
- And many more!