My First Code Snippet

My First Code Snippet

· 1 min read

Code Blocks

This post tests the rich code block features including syntax highlighting, line numbers, and the copy button.

JavaScript Example

function greet(name) {
  const message = `Hello, ${name}!`;
  console.log(message);
  return message;
}

// Usage
greet("World");

TypeScript Example

interface Post {
  title: string;
  date: Date;
  tags: string[];
  draft?: boolean;
}

function createPost(title: string, tags: string[]): Post {
  return {
    title,
    date: new Date(),
    tags,
  };
}

CSS Example

:root {
  --primary: oklch(0.5 0.2 250);
  --spacing: 1rem;
}

.container {
  max-width: 75ch;
  margin-inline: auto;
  padding: var(--spacing);
}

How It Works

  1. Write code in fenced blocks with a language identifier
  2. Add title="filename" metadata for filename display
  3. Hover over the code block to reveal the copy button
  4. Click to copy — you’ll see “Copied!” feedback

That’s it! Clean and simple.