Format and lint markdown and MDX files using markdownlint with comprehensive rule knowledge for automated and manual fixes. Use when working with .md or .mdx files, formatting documentation, linting markdown/MDX, or when user mentions markdown issues, formatting problems, or documentation standards.
Format and lint markdown and MDX files using markdownlint CLI tools with comprehensive understanding of all markdown rules.
# Check if markdownlint is available
which markdownlint || which markdownlint
# Install if needed
pnpm add -D markdownlint
# or
npm install -g markdownlint
# Auto-fix files (markdown and MDX)
markdownlint --fix "**/*.{md,mdx}"
# Check specific files
markdownlint README.md docs/**/*.md content/**/*.mdx
Check for config files in this order:
.markdownlint.json.markdownlint.jsonc.markdownlint.yaml.markdownlintrcmarkdownlint key in package.json# Heading not #Heading)<!-- Good heading structure -->
# Main Title
## Section
### Subsection
Content here...
- or all *)<!-- Good list structure -->
- Item 1
- Nested item
- Another nested
- Item 2
<>: <http://example.com>[Link Text](url) not [](url)<!-- Good code block -->
Text before
```javascript
const code = 'here';
```
Text after
# Fix all markdown and MDX files
markdownlint --fix "**/*.{md,mdx}"
# Fix specific files
markdownlint --fix README.md CHANGELOG.md content/blog.mdx
# Check without fixing
markdownlint "**/*.{md,mdx}"
# Use specific config
markdownlint --config .markdownlint.json "**/*.{md,mdx}"
# Ignore specific rules
markdownlint --disable MD013 MD033 "**/*.{md,mdx}"
# Output JSON for parsing
markdownlint --json "**/*.{md,mdx}"
<!-- Before -->
#Title
Some text with trailing spaces
Tab indented line
- Item 1
* Item 2
Visit http://example.com
<!-- After -->
# Title
Some text with trailing spaces
Space indented line
- Item 1
- Item 2
Visit <http://example.com>
{
"scripts": {
"lint:md": "markdownlint \"**/*.{md,mdx}\" --ignore node_modules",
"lint:md:fix": "markdownlint \"**/*.{md,mdx}\" --ignore node_modules --fix"
}
}
For comprehensive documentation of all markdown rules with examples and fixes, see rules-reference.md.