Skip to main content
rule

mkdocs — Cursor rule: documentation and setup

Sets conventions for MkDocs documentation with the Material theme. Use it to organize page navigation and catch issues before building the site.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/mkdocs.mdc
Open on GitHub

What mkdocs does

The rule covers project layout, Markdown conventions, and documentation checks. It applies to md and mdx files, recommends keeping mkdocs.yml at the project root, and puts source pages in docs/ with index.md as the homepage. Navigation uses .pages files and mkdocs-awesome-pages-plugin rather than alphabetical ordering.

Pages should have one H1, follow heading levels in sequence, and keep text lines within 80 characters. Use relative paths for internal links, language-labelled fenced blocks for code, and Material for MkDocs admonitions for notes and warnings. For CI, the rule suggests markdownlint and mkdocs-code-validator; test locally with mkdocs serve. An invalid .pages file prevents the site from building, so navigation edits need a check.

What it helps with

  • organize MkDocs pages and define a homepage
  • set page order through .pages files
  • check heading levels and line length
  • format links, code blocks, and admonitions consistently
  • add Markdown linting and code validation to CI

Example prompts for the agent

  • Review the Markdown docs and fix issues covered by the MkDocs rule.
  • Set up project navigation with .pages, then check it using mkdocs serve.
  • Check whether CI runs markdownlint and mkdocs-code-validator.

How to install mkdocs

Manually: put the files in place

.cursor/rules/mkdocs.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about mkdocs

How do I install mkdocs in Cursor?

Add the rule file to your project at .cursor/rules/mkdocs.mdc.

What does the mkdocs rule do?

It sets conventions for MkDocs project structure, Markdown formatting, links, navigation, and documentation checks.

Which checks does the rule recommend?

It suggests running markdownlint and mkdocs-code-validator in CI, and testing locally with mkdocs serve. Invalid .pages syntax can prevent the site build.

Source text

mkdocs.mdc · CC0-1.0
---
description: Definitive guidelines for writing, structuring, and maintaining high-quality MkDocs documentation using modern best practices and Material for MkDocs.
globs: **/*.{md,mdx}
---
# mkdocs Best Practices

This guide establishes the definitive standards for writing and maintaining documentation using MkDocs, especially with the Material for MkDocs theme. Adhere to these rules to ensure consistency, readability, and maintainability across all our projects.

## 1. Code Organization & Structure

Always organize your documentation for logical navigation and maintainability.

### 1.1 Root Structure

Place `mkdocs.yml` at the project root, and all Markdown source files within a top-level `docs/` directory. The homepage must be `index.md`.

❌ BAD:
```
my-project/
├── docs/
│   ├── mkdocs.yml  # mkdocs.yml should be at project root
│   └── homepage.md # Homepage should be index.md
```

✅ GOOD:
```
my-project/
├── mkdocs.yml
└── docs/
    ├── index.md
    └── user-guide/
        └── getting-started.md
```

### 1.2 Navigation Ordering

Control navigation explicitly using the `mkdocs-awesome-pages-plugin` and `.pages` files. Never rely on default alphabetical ordering.

❌ BAD:
```
# mkdocs.yml
nav:
  - Home: index.md
  - API: api.md
  - Setup: setup.md # Order is alphabetical, not logical
```

✅ GOOD:
```
# docs/.pages
nav:
  - Home: index.md
  - Setup: setup.md
  - API: api.md
  - ... # Include remaining pages automatically
```

## 2. Markdown Style & Content

Enforce a strict Markdown style for readability and consistency, ideally with `markdownlint`.

### 2.1 Headings Hierarchy

Use a single H1 (`#`) per page for the main title. Subsequent headings must follow a strict, sequential hierarchy (H2, H3, etc.). Never skip heading levels.

❌ BAD:
```markdown
# My Page Title
### A Sub-section # Skipped H2
```

✅ GOOD:
```markdown
# My Page Title
## Introduction
### Key Concepts
```

### 2.2 Line Length

Limit text lines to 80 characters for improved readability and diffs. Exceptions are allowed for long URLs, tables, and code blocks.

❌ BAD:
```markdown
This is a very long line of text that exceeds eighty characters and makes it difficult to read and review, especially in side-by-side diffs.
```

✅ GOOD:
```markdown
This is a standard line of text that adheres to the eighty-character limit.
It improves readability and simplifies code reviews.
```

### 2.3 Fenced Code Blocks

Always use fenced code blocks with language identifiers for syntax highlighting. Never use indented code blocks.

❌ BAD:
```markdown
    This is an indented code block.
    It lacks syntax highlighting and is harder to read.
```

✅ GOOD:
```python
def hello_world():
    print("Hello, MkDocs!")
```

### 2.4 Internal Links

Use relative paths for all internal links to Markdown files. MkDocs automatically converts these to correct HTML paths.

❌ BAD:
```markdown
Please see the [Getting Started](/user-guide/getting-started/) guide. # Absolute path
Please see the [Getting Started](https://example.com/user-guide/getting-started.md) guide. # Full URL
```

✅ GOOD:
```markdown
Please see the [Getting Started](user-guide/getting-started.md) guide. # Relative path
```

### 2.5 External Links & Buttons

Mark external links to open in a new tab using `{target=_blank}`. Use Material for MkDocs button syntax for prominent calls to action.

❌ BAD:
```markdown
[Our GitHub](https://github.com/our-org) # Opens in same tab
<a href="https://github.com/our-org" class="button">GitHub</a> # Raw HTML
```

✅ GOOD:
```markdown
[Our GitHub](https://github.com/our-org){target=_blank}
[Visit Our Blog](https://practical.li/blog){.md-button .md-button-primary target=_blank}
```

### 2.6 Admonitions

Use Material for MkDocs admonitions for notes, warnings, and tips. Never use blockquotes for this purpose.

❌ BAD:
```markdown
> **Warning:** This action is irreversible.
```

✅ GOOD:
```markdown
!!! warning "Irreversible Action"
    This action is irreversible. Proceed with caution.
```

## 3. Performance & Maintainability

Prioritize automated checks and efficient content delivery.

### 3.1 Automated Linting & Validation

Integrate `markdownlint` and `mkdocs-code-validator` into your CI pipeline. This catches style violations and validates code snippets automatically.

❌ BAD: Relying solely on manual review for Markdown style and code correctness.

✅ GOOD:
```yaml
# .github/workflows/ci.yml
name: Docs CI
on: [push, pull_request]
jobs:
  lint-docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: avto-dev/markdown-lint@v1 # markdownlint
      - uses: actions/setup-python@v3
        with:
          python-version: '3.x'
      - run: pip install mkdocs mkdocs-material mkdocs-code-validator
      - run: mkdocs build --strict # mkdocs-code-validator runs during build
```

## 4. Common Pitfalls & Gotchas

Avoid these common mistakes to prevent broken documentation.

### 4.1 Broken Navigation

An invalid `.pages` file will prevent your site from building. Always test changes locally with `mkdocs serve`.

❌ BAD:
```yaml
# docs/.pages (invalid syntax)
nav:
  - Introduction: intro.md
  - Section 1
    - Page 1: page1.md # Incorrect indentation
```

✅ GOOD:
```yaml
# docs/.pages
nav:
  - Introduction: intro.md
  - Section 1:
    - Page 1: page1.md
```

### 4.2 Raw HTML Usage

Avoid embedding raw HTML unless absolutely necessary (e.g., specific embeds like YouTube videos). Prefer Markdown and Material for MkDocs extensions.

❌ BAD:
```markdown
<p style="color: red;">Important text</p>
```

✅ GOOD:
```markdown
!!! danger "Important"
    Important text
```

© sanjeed5 · CC0-1.0 · sanjeed5/awesome-cursor-rules-mdc

Similar IDE rules

All IDE rules for Writing and docs →

From the same set240

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor