Robert's avatar

Code by Robert

GitHub Flavored Markdown & MDX Demo

GitHub Flavored Markdown & MDX Demo

This article demonstrates all the GitHub Flavored Markdown (GFM) features supported by remark-gfm, plus some basic MDX capabilities.

GFM automatically converts URLs and email addresses into clickable links:

Tables

GFM supports tables with alignment options:

FeatureSupportedPriorityNotes
TablesYesHighEssential
Task ListsYesHighVery useful
StrikethroughYesMediumNice to have
FootnotesYesLowAdvanced

Task Lists

How to use task lists

Track your progress with interactive task lists:

  • Set up Astro project
  • Install @astrojs/mdx integration
  • Configure remark-gfm plugin
  • Write comprehensive documentation
  • Add more examples
  • Deploy to production

Strikethrough

You can mark text as deleted or incorrect:

  • This is wrong information
  • Single tilde also works (if singleTilde: true)
  • The correct answer is 42 43

Footnotes

GFM supports footnotes for additional context1. You can reference them inline2 and they’ll appear at the bottom of the document.

Code Examples

Inline code: const greeting = 'Hello, World!';

Block code with syntax highlighting:

interface User {
    id: number;
    name: string;
    email: string;
}

function greetUser(user: User): string {
    return `Hello, ${user.name}!`;
}

const currentUser: User = {
    id: 1,
    name: 'Robert',
    email: 'robert@example.com',
};

console.log(greetUser(currentUser));
// JavaScript example
const fetchData = async (url) => {
    try {
        const response = await fetch(url);
        const data = await response.json();
        return data;
    } catch (error) {
        console.error('Error fetching data:', error);
    }
};

IMAGE

Astro Logo

MDX Capabilities

MDX allows you to use JSX directly in your markdown content.

Inline JSX Elements

Here’s some text with inline styled content using JSX.

You can also use HTML elements: highlighted text and Ctrl + C for keyboard shortcuts.

Expressions

MDX supports JavaScript expressions: 2 + 2 = 4 and the current year is 2025.

Blockquotes

Note: This is an important note using a blockquote.

GFM and MDX work seamlessly together in Astro, providing a powerful content authoring experience.

Warning: Make sure to install both @astrojs/mdx and remark-gfm for full functionality.

Horizontal Rules

You can use horizontal rules to separate sections:


Lists

Unordered Lists

  • First item
  • Second item
    • Nested item 1
    • Nested item 2
      • Deeply nested item
  • Third item

Ordered Lists

  1. First step
  2. Second step
    1. Sub-step A
    2. Sub-step B
  3. Third step

Emphasis

  • Italic text or italic text
  • Bold text or bold text
  • Bold and italic or bold and italic
  • Strikethrough text

Visit Astro Documentation

Link with title

Definition Lists

While not part of standard GFM, you can still write definition-style content:

Term 1 : Definition for term 1

Term 2 : Definition for term 2 : Another definition for term 2

GitHub Alerts

GitHub-style alerts provide a way to emphasize critical information using special blockquote syntax:

NOTE

Useful information that users should know, even when skimming content.

TIP

Helpful advice for doing things better or more easily.

IMPORTANT

Key information users need to know to achieve their goal.

WARNING

Urgent info that needs immediate user attention to avoid problems.

CAUTION

Advises about risks or negative outcomes of certain actions.

Mathematical Expressions with KaTeX

You can write inline math like E=mc2E = mc^2 or i=1nxi\sum_{i=1}^{n} x_i directly in your markdown.

For display math, use double dollar signs:

ex2dx=π\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}

You can also write complex equations:

F=ma(1)Ek=12mv2(2)\begin{array}{l r} F = ma & \text{(1)} \\ E_k = \frac{1}{2}mv^2 & \text{(2)} \end{array}

Summary

This document demonstrates:

  1. ✅ Autolink literals (URLs and emails)
  2. ✅ Tables with alignment
  3. ✅ Task lists
  4. ✅ Strikethrough text
  5. ✅ Footnotes
  6. ✅ Code blocks with syntax highlighting
  7. ✅ Inline JSX elements (MDX feature)
  8. ✅ JavaScript expressions (MDX feature)
  9. ✅ GitHub-style alerts (NOTE, TIP, IMPORTANT, WARNING, CAUTION)
  10. ✅ KaTeX math rendering (inline and block)

All of these features work together seamlessly in Astro with the @astrojs/mdx integration, remark-gfm, remark-math, remark-github-blockquote-alert, and rehype-katex plugins configured in astro.config.mjs.

MDX Variables and Expressions

MDX allows you to define and use JavaScript variables within your markdown:

這篇文章由 Gemini 寫於 2025 年。

Footnotes

  1. This is the first footnote with some additional information.

  2. Footnotes can contain formatted text and even code snippets.

© Code by Robert