MDX Syntax Best Practices and Error Prevention
This guide documents common MDX parsing errors in Mintlify documentation and how to prevent them.Common Errors and Solutions
1. Unescaped Angle Brackets Before/After Numbers
Error:Unexpected character '1' (U+0031) before name
Cause: Using < or > directly before numbers (e.g., <100K, >1M)
Solution: Use HTML entities
❌ Wrong:
python scripts/fix_mdx_angle_brackets.py
2. Missing Blank Lines Around Component Tags
Error:Expected a closing tag for <CodeGroup>
Cause: Missing blank lines after opening or before closing component tags
Solution: Always add blank lines
❌ Wrong:
<CodeGroup><Accordion><AccordionGroup><Tabs>/<Tab><Card>/<CardGroup><Steps>/<Step>
3. Stray Language Tags After Code Blocks
Error: Various parsing errors Cause: Accidentalxml or other language tags after closing triple backticks
Solution: Remove stray language tags
❌ Wrong:
find . -name "*.mdx" -exec sed -i 's/```xml$/```/g' {} \;
4. Heredoc Syntax in Code Blocks
Error:Unexpected closing slash '/' in tag
Cause: Using heredoc syntax with quotes that confuse the MDX parser
Solution: Use separate code blocks or avoid heredoc quotes
❌ Problematic:
5. Unclosed or Mismatched Tags
Error:Expected a closing tag for <Accordion>
Cause: Missing closing tags or tags closed in wrong order
Solution: Ensure all tags are properly matched
❌ Wrong (missing closing tag):
python scripts/validate_mdx_syntax.py
Preventive Scripts
1. Fix Angle Brackets
2. Validate MDX Syntax
3. Remove Stray XML Tags
4. Run Mintlify Link Checker
Pre-Commit Checklist
Before committing MDX files:- Run
python scripts/fix_mdx_angle_brackets.py - Run
python scripts/validate_mdx_syntax.py --fix - Run
mintlify broken-linksto verify no parsing errors - Check for stray
xml tags: `grep -r 'xml’ docs/ —include=“*.mdx”` - Verify blank lines around all component tags
Common Patterns to Avoid
Shell Commands with Quotes
Instead of using heredoc syntax with quotes in code blocks, use separate blocks: Instead of this:patch.yaml:
Comparison Operators
Always escape comparison operators when followed by numbers:- ✅ Use: < and >
- ❌ Avoid: < and >
Component Nesting
Keep component nesting clean and well-spaced:Automated CI/CD Integration
Add to.github/workflows/docs-validation.yml:
Emergency Fixes
Ifmintlify broken-links fails:
- Note the file and line number from the error
- Run validation on that specific file:
- Check for common issues in order:
- Unescaped
<or>before numbers - Missing blank lines around components
- Stray ````xml` tags
- Heredoc syntax with quotes
- Unclosed/mismatched tags
- Unescaped
- Fix and re-run
mintlify broken-links
Additional Resources
- Mintlify MDX Documentation
- MDX Specification
- Project scripts:
/scripts/fix_mdx_angle_brackets.py/scripts/validate_mdx_syntax.py/scripts/add_code_block_lang_tags.py