Mdx sanitizer

From curiositech/windags-skills · View interactive version

Mdx sanitizer is an AI agent skill from the GitHub repository curiositech/windags-skills. Comprehensive MDX content sanitizer that escapes angle brackets, generics, and other JSX-conflicting patterns to prevent build failures

How to use this skill

Skill file

MDX Sanitizer

Comprehensive MDX content sanitizer that prevents JSX parsing errors caused by angle brackets, generics, and other conflicting patterns.

Decision Points

When to sanitize vs validate vs wrap:

Content Analysis:
├── Inside code blocks (```, `)
│   └── → Skip sanitization (already protected)
├── Contains TypeScript generics (`Promise<T>`)
│   └── → Sanitize with HTML entities
├── Contains comparisons (`<100ms`, `<=`)
│   └── → Sanitize with HTML entities  
├── Contains arrows (`->`, `<--`)
│   └── → Sanitize with HTML entities
├── Valid JSX components (PascalCase)
│   └── → Skip sanitization (preserve functionality)
├── Valid HTML5 elements (`<div>`, `<span>`)
│   └── → Skip sanitization (preserve functionality)
├── Invalid pseudo-tags (`<link>` in prose)
│   └── → Sanitize with HTML entities
└── Documentation examples
    ├── If showing code syntax → Wrap in code blocks
    └── If showing output/prose → Sanitize with HTML entities

Content type decision matrix:

| Pattern | Action | Reason |

|---------|--------|--------|

| Promise<T> | Sanitize | TypeScript generic, not JSX |

| <MyComponent> | Skip | Valid JSX component |

| <div> | Skip | Valid HTML5 element |

| <link> in prose | Sanitize | Invalid context for HTML |

| <100ms | Sanitize | Comparison, not JSX |

| ` <T> ` | Skip | Already in code block |

Failure Modes

Schema Bloat: Over-sanitizing valid JSX

Escape Cascade: Double-escaping already sanitized content

Code Block Pollution: Sanitizing content that should stay literal

Context Blindness: Wrong sanitization strategy for content type

Validation Bypass: Files passing validation but failing build

Worked Examples

Scenario 1: TypeScript API Documentation

Input content:

The `createMap` function returns `Promise<Map<string, User>>` where each User has...
Performance is <100ms for datasets <=1000 items.

Decision process:

  1. Scan for code blocks → None found
  2. Identify patterns → Promise<Map<string, User>>, <100ms, <=1000
  3. Check if valid JSX → No, these are TypeScript generics and comparisons
  4. Apply HTML entity escaping

Output:

The `createMap` function returns `Promise&lt;Map&lt;string, User&gt;&gt;` where each User has...
Performance is &lt;100ms for datasets &lt;=1000 items.

Expert insight: Novice might wrap entire line in code block, losing prose flow. Expert selectively escapes only the problematic characters while preserving readability.

Scenario 2: Component Usage Guide

Input content:

Use <Button variant="primary"> for main actions.
The <link> tag should be avoided in favor of <Link>.

Decision process:

  1. Analyze first pattern → <Button variant="primary"> has PascalCase, valid JSX
  2. Skip sanitization for Button component
  3. Analyze second pattern → <link> in prose context, not valid JSX usage
  4. Sanitize invalid tag references

Output:

Use <Button variant="primary"> for main actions.  
The &lt;link&gt; tag should be avoided in favor of <Link>.

Trade-off analysis: Preserving functional JSX while sanitizing prose references maintains both functionality and safety.

Quality Gates

NOT-FOR Boundaries

This skill is NOT for:

Delegation patterns:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.