MDX - Component-Enhanced Markdown
September 5, 2024
:85 :0
Introduction to Markdown
Markdown is a lightweight markup language using simple syntax to create structured text documents that convert seamlessly to HTML. Widely adopted for README files, its readability and ease of use make it ideal for web applications, forums, blogs, documentation, and e-books.
Core Markdown Syntax
Create a .md
file (e.g., README.md
) and use these essential syntax patterns:
Headers (use #
with space separation)
# Header Level 1
## Header Level 2
### Header Level 3
#### Header Level 4
##### Header Level 5
###### Header Level 6
Text Formatting
*Italic* or _Italic_
**Bold** or __Bold__
***Bold-Italic*** or ___Bold-Italic___
Links
[Link Text](https://www.example.com)
Images

Blockquotes
> This is a quoted text block
Lists
Ordered:
1. First item
2. Second item
3. Third item
Unordered (use -
, +
, or *
):
- Item A
+ Item B
* Item C
Code Blocks
Inline code: `console.log()`
Multi-line blocks:
```js
console.log('Hello World')
```
MDX: Supercharged Markdown
MDX combines Markdown with JSX, enabling import
/export
statements, JSX components, expressions {}
, and custom components:
import CodeBlock from '../../components/CodeBlock.astro';
export const config = `/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{html,js}'],
theme: { extend: {} },
plugins: [],
}`
<CodeBlock lang="json" code={config} />
Renders as:
/** @type {import('tailwindcss').Config} */
export default {
content: ['./src/**/*.{html,js}'],
theme: { extend: {} },
plugins: [],
}
Key Advantages of MDX
1. **Component Integration**
Embed React/Vue components directly in documentation
2. **Dynamic Content**
Use JavaScript expressions: `Current date: {new Date().toLocaleString()}`
3. **Frontmatter Support**
Manage metadata with YAML frontmatter
4. **Framework Agnostic**
Works with React, Vue, Svelte, and static site generators
Pro Tip: MDX maintains all standard Markdown features while adding component capabilities
For advanced implementations, refer to the Official MDX Documentation.