Documentation Style Guide¶
This guide outlines the standards and best practices for writing documentation for EgyGeeks projects.
Code Blocks¶
Basic Syntax¶
Always specify the language for syntax highlighting:
Supported Languages¶
Common languages we use: - python - Python code - javascript or js - JavaScript - typescript or ts - TypeScript - bash or sh - Shell scripts - yaml - YAML configuration files - json - JSON data - sql - SQL queries - go - Go code - html - HTML markup - css - CSS stylesheets - dockerfile - Dockerfiles - nginx - Nginx configuration
Adding Titles¶
Use title to show the filename or description:
When to use titles: - Always add titles to show actual filenames - For configuration files (e.g., title="mkdocs.yml") - For scripts (e.g., title="deploy.sh") - For code examples that represent complete files
Line Numbers¶
Add line numbers with linenums="1":
```python linenums="1"
def bubble_sort(items):
for i in range(len(items)):
# sorting logic
return items
```
When to use line numbers: - For longer code examples (>5 lines) - When discussing specific line numbers in the text - For complete functions or classes - For configuration files
Highlighting Lines¶
Emphasize important lines with hl_lines:
```python linenums="1" hl_lines="2 3"
def connect_db():
conn = create_connection() # Important
conn.set_timeout(30) # Important
return conn
```
You can highlight ranges too:
When to highlight lines: - To draw attention to important changes - To show the specific lines being discussed - To highlight security-critical code - To show configuration that needs customization
Code Annotations¶
Add explanatory notes using numbered markers:
```python linenums="1"
def api_call(url, token): # (1)!
headers = {
"Authorization": f"Bearer {token}", # (2)!
"Content-Type": "application/json"
}
return requests.get(url, headers=headers, timeout=30) # (3)!
```
1. Main API function that handles authenticated requests
2. Authentication header with bearer token
3. 30-second timeout prevents hanging requests
Best practices for annotations: - Use (1)! format (with exclamation) to hide comment markers - Place annotations after the code block - Keep explanations concise but informative - Number them sequentially
Inline Code¶
Use backticks for inline code references:
For syntax-highlighted inline code:
Complete Example¶
Here's a code block using all features:
```python title="database.py" linenums="1" hl_lines="8-10"
import psycopg2
from typing import Optional
class Database:
"""Database connection handler."""
def __init__(self, connection_string: str): # (1)!
self.conn = psycopg2.connect(connection_string)
self.cursor = self.conn.cursor()
self._setup_connection() # (2)!
def _setup_connection(self):
"""Configure connection parameters."""
self.cursor.execute("SET timezone TO 'UTC'")
self.conn.commit()
def close(self): # (3)!
self.cursor.close()
self.conn.close()
```
1. Initialize database connection with connection string
2. Setup method configures timezone and other parameters
3. Always close connections to prevent resource leaks
Admonitions¶
Use admonitions to highlight important information:
Note¶
Tip¶
Warning¶
Danger¶
Info¶
Example¶
Collapsible Admonitions¶
Use ??? for collapsed-by-default admonitions:
Use ???+ for expanded-by-default but collapsible:
Content Tabs¶
Group related content with tabs:
=== "Python"
```python
print("Hello, World!")
```
=== "JavaScript"
```javascript
console.log("Hello, World!");
```
=== "Go"
```go
fmt.Println("Hello, World!")
```
When to use tabs: - Showing the same example in multiple languages - Comparing different approaches - OS-specific instructions (Linux/macOS/Windows)
Task Lists¶
Create interactive checklists:
Tables¶
Create clear, formatted tables:
| Feature | Status | Notes |
|---------|--------|-------|
| Authentication | ✅ Done | OAuth2 supported |
| Caching | 🚧 In Progress | Redis integration |
| Logging | ✅ Done | Structured logging |
Links¶
Internal Links¶
Link to other documentation pages:
External Links¶
Reference Links¶
For repeated links:
Check out [Material for MkDocs][mkdocs-material] documentation.
[mkdocs-material]: https://squidfunk.github.io/mkdocs-material/
Images¶
Add images with captions:
Keyboard Keys¶
Show keyboard shortcuts:
Abbreviations¶
Define abbreviations in your content:
The HTML specification is maintained by W3C.
*[HTML]: Hypertext Markup Language
*[W3C]: World Wide Web Consortium
Common abbreviations are auto-included from includes/abbreviations.md.
Formatting Best Practices¶
Headers¶
- Use
#for page title (only one per page) - Use
##for main sections - Use
###for subsections - Use
####for sub-subsections (rarely needed)
Lists¶
Unordered lists:
Ordered lists:
Emphasis¶
*Italic text* or _italic text_
**Bold text** or __bold text__
***Bold and italic*** or ___bold and italic___
~~Strikethrough~~
==Highlighted text==
Blockquotes¶
File Organization¶
Naming Conventions¶
- Use lowercase with hyphens:
api-reference.md - Be descriptive:
docker-deployment-guide.md - Avoid special characters except hyphens
Front Matter¶
Add metadata at the top of files:
---
title: Custom Page Title
description: Brief description for SEO
tags:
- api
- authentication
- security
---
# Page Content
Writing Style¶
Voice and Tone¶
- Use clear, concise language
- Write in second person ("you") when addressing readers
- Use active voice over passive voice
- Be helpful and friendly but professional
Code Examples¶
- Always test code examples before documenting
- Include error handling where relevant
- Add comments for complex logic
- Show complete, working examples when possible
Security¶
- Never include real API keys, passwords, or secrets
- Use placeholders:
YOUR_API_KEY,<your-token>, etc. - Highlight security best practices
- Warn about common security pitfalls
Mermaid Diagrams¶
Create diagrams with Mermaid:
Flow Diagram¶
```mermaid
graph LR
A[Client] --> B[API Gateway]
B --> C[Service 1]
B --> D[Service 2]
C --> E[Database]
D --> E
### Sequence Diagram
```markdown
```mermaid
sequenceDiagram
User->>API: Request
API->>Database: Query
Database->>API: Result
API->>User: Response
Quick Reference¶
| Element | Syntax |
|---|---|
| Code block with title | ```python title="app.py" |
| Line numbers | ```python linenums="1" |
| Highlight lines | ```python hl_lines="2 3" |
| Inline code | `code` |
| Syntax inline | `#!python code` |
| Note | !!! note |
| Warning | !!! warning |
| Tab group | === "Tab Name" |
| Task list | - [ ] Task |
| Keyboard | ++ctrl+c++ |
| Abbreviation | *[HTML]: Hypertext Markup Language |
Examples¶
For more examples, see:
Remember: Good documentation helps your teammates understand and use our tools effectively. Take time to make it clear, accurate, and helpful!