Skip to main content

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:
Correct:
Automated Fix: Run 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:
Correct:
Components requiring blank lines:
  • <CodeGroup>
  • <Accordion>
  • <AccordionGroup>
  • <Tabs> / <Tab>
  • <Card> / <CardGroup>
  • <Steps> / <Step>

3. Stray Language Tags After Code Blocks

Error: Various parsing errors Cause: Accidental xml or other language tags after closing triple backticks Solution: Remove stray language tags ❌ Wrong:
Automated Fix: 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:
✅ Better:
Then show the patch file separately:

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):
Correct:
Validation: Run python scripts/validate_mdx_syntax.py

Preventive Scripts

1. Fix Angle Brackets

2. Validate MDX Syntax

3. Remove Stray XML Tags

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-links to 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:
Do this: First create patch.yaml:
Then apply:

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

If mintlify broken-links fails:
  1. Note the file and line number from the error
  2. Run validation on that specific file:
  3. 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
  4. Fix and re-run mintlify broken-links

Additional Resources