Code Block Style Guide
Guidelines for formatting code blocks in WebMCP documentation using Mintlify features
Table of Contents
- Overview
- Quick Reference
- Core Principles
- Formatting Options
- Icon Reference
- Examples by Use Case
- Migration Guide
- Mintlify Documentation
Overview
This guide documents the code formatting standards for WebMCP documentation. We use Mintlify’s advanced code block features to improve readability, navigation, and learning experience. Mintlify Docs: Format codeQuick Reference
Basic Syntax
Common Patterns
| Use Case | Pattern | Example |
|---|---|---|
| React example | tsx "Component.tsx" twoslash lines icon="react" | Component code with types |
| Install command | bash icon="npm" | npm/pnpm commands |
| Good/bad comparison | javascript lines with // [!code ++] and // [!code --] | Visual diffs |
| Long example | typescript "example.ts" expandable lines | Collapsible code |
| API reference | typescript "api.ts" lines icon="code" | Reference documentation |
Core Principles
1. Always Specify Language
Every code block must have a language identifier for syntax highlighting.3. Add Icons for Visual Clarity
Use icons to help users quickly identify the technology or context.5. Use twoslash for TypeScript
Enable hover type information for TypeScript and TSX examples.
Highlight
Highlights specific lines or ranges to draw attention. When to use:- Drawing attention to new or changed code
- Focusing on the most important parts
- Teaching specific concepts
highlight={1,3-5,8}
Focus
Dims everything except specified lines (opposite of highlight). When to use:- When you want to hide boilerplate
- Focusing on a specific section of a larger example
- Progressive disclosure in tutorials
focus={2,4-5}
Expandable
Makes long code blocks collapsible. When to use:- Code examples over 50 lines
- Complete implementations that might overwhelm the page
- Reference code that users may want to skip
expandable
Diff (Visual Red/Green)
Shows additions and deletions with colored highlighting. When to use:- Good vs. bad pattern comparisons
- Before/after examples
- Migration guides
- Deprecation warnings
// [!code ++]- Mark line as added (green)// [!code --]- Mark line as removed (red)// [!code ++:3]- Mark current line + next 2 as added
Wrap
Enables text wrapping for long lines. When to use:- Long URLs or strings
- Examples where horizontal scrolling would be annoying
- Mobile-friendly code blocks
wrap
Twoslash
Enables TypeScript hover type information (TypeScript/TSX only). When to use:- All TypeScript examples where type information adds value
- Complex TypeScript patterns
- Teaching TypeScript concepts
- API documentation with types
twoslash
Icon Reference
Technology Icons
Use these icons to indicate the technology stack:| Icon | Use For | Example |
|---|---|---|
icon="react" | React code, React packages | tsx files, @mcp-b/react-webmcp |
icon="node" | Node.js code, npm packages | Server-side JS, npm install |
icon="npm" | Package installation | npm install, pnpm add |
icon="square-js" | Vanilla JavaScript | Plain JS, no framework |
icon="code" | Generic code/HTML | HTML examples, mixed code |
icon="terminal" | Terminal commands | CLI commands, shell scripts |
Pattern Icons
Use these icons to indicate the pattern or purpose:| Icon | Use For | Example |
|---|---|---|
icon="server" | Server setup, backend | MCP server initialization |
icon="plug" | Client connection, API | MCP client setup |
icon="window" | Iframe child/content | Code inside iframe |
icon="window-maximize" | Parent page/container | Parent page code |
icon="layer-group" | Hub/aggregator | Extension background script |
icon="bridge" | Bridge/proxy pattern | Content script bridge |
icon="sidebar" | UI components | Extension sidepanel |
icon="bolt" | Performance optimization | Optimistic updates |
icon="shield" | Security patterns | Auth, validation |
icon="check" | Good patterns | Best practice examples |
icon="x" | Anti-patterns | What to avoid |
Examples by Use Case
1. React Component Example
- ✅
twoslashenables hover types - ✅ Title shows filename
- ✅
linesfor reference - ✅
icon="react"immediately identifies React - ✅
highlightdraws attention to the hook usage
2. Installation Command
- ✅ Simple, no unnecessary options
- ✅ Icon indicates package manager context
3. Good vs. Bad Pattern Comparison
- ✅ Visual red/green immediately shows good vs. bad
- ✅ Comments explain why
- ✅
lineshelps discuss specific patterns
4. Long Reference Implementation
- ✅
expandableprevents overwhelming the page - ✅
twoslashprovides types for reference - ✅
linesfor citation - ✅ Icon shows it’s server code
5. Server/Client Paired Examples
Use consistent titles and icons to show relationships:- ✅ Matching title format shows they’re related
- ✅ Different icons (
servervsplug) show roles - ✅ Consistent formatting aids understanding
6. Security or Performance Pattern
- ✅
icon="bolt"indicates performance focus - ✅
highlightshows the key optimization - ✅ Comments explain the pattern
Migration Guide
Converting Existing Code Blocks
Step 1: Identify the Purpose
Ask yourself:- Is this TypeScript/TSX? → Add
twoslash - Is this a reference example? → Add
linesand a title - Is this showing good vs. bad? → Use diff syntax
- Is this over 50 lines? → Add
expandable - Does this need visual identification? → Add an icon
Step 2: Choose Appropriate Options
Don’t overdo it. Start minimal and add options that provide value: Minimal (install command):Step 3: Update Icons and Titles
Replace generic patterns with specific ones: Before:Converting Good/Bad Patterns
Before (using comments):Mintlify Documentation
Official References
- Main Guide: Format code
- Syntax Highlighting: Languages (Shiki)
- Themes: Shiki Themes
- Icons: Available icons
Key Mintlify Pages
Best Practices Summary
Do
- ✅ Always specify a language for syntax highlighting
- ✅ Use
twoslashfor TypeScript examples - ✅ Add titles to major code examples (not trivial ones)
- ✅ Use icons to provide visual context
- ✅ Use
linesfor reference documentation - ✅ Make long examples (50+ lines) expandable
- ✅ Use diff syntax for good vs. bad comparisons
- ✅ Highlight key lines in teaching examples
- ✅ Keep titles concise (filename or brief description)
Don’t
- ❌ Add titles to trivial one-liners
- ❌ Use
twoslashon non-TypeScript code - ❌ Over-highlight (highlight sparingly for impact)
- ❌ Use diff syntax for everything (only comparisons)
- ❌ Forget to test code examples
- ❌ Use outdated or incorrect code in examples
- ❌ Mix different formatting styles on the same page
Questions?
If you’re unsure about formatting:- Check this guide first
- Look at similar examples in existing docs (quickstart.mdx, best-practices.mdx, transports.mdx)
- Start minimal and add features that provide clear value
- Refer to the Mintlify docs
Last Updated: 2025-11-05 Pilot Implementation: quickstart.mdx, best-practices.mdx, packages/transports.mdx
