MDX Syntax Guide
MDX lets you write familiar Markdown while adding components and JavaScript expressions where ordinary Markdown is not enough. This guide introduces the syntax that is most useful when authoring an article in Mizuki.
NOTEWhat is MDX?
An
.mdxfile is still a Markdown document. Headings, lists, links, images, code blocks, and other Markdown syntax continue to work, while imports, components, JSX, and expressions become available as optional extensions.
Frontmatter
Every article begins with YAML frontmatter. It defines metadata used by article pages, lists, search results, and feeds:
---title: My MDX Articlepublished: 2026-08-08description: A short introduction shown in article previews.tags: [Markdown, MDX]category: Guidesdraft: false---Keep frontmatter focused on metadata. Imports and JavaScript declarations
belong immediately after the closing --- delimiter.
Standard Markdown
Most of an MDX article should remain ordinary Markdown. This keeps the source easy to read and gives RSS and Atom readers a useful static version.
## A section heading
- A list item- **Bold text** and *emphasis*- [A normal link](https://example.com/)
> A blockquote remains a blockquote.Importing and Using Components
MDX can import Astro components at the top level and use them directly in the document. Component names must begin with a capital letter.
import Notice from "../../components/Notice.astro";
export const message = "Props can come from an MDX expression.";
<Notice label={message} />The following panel is a live component rendered by this article:
Use components for reusable interface elements or structured content. Prefer Markdown for regular prose so the article remains portable and readable.
JavaScript Expressions
Top-level export const declarations can prepare values for the document.
Insert a JavaScript expression with braces:
export const topics = ["components", "expressions", "extended Markdown"];
This guide covers {topics.length} topics: {topics.join(", ")}.This live expression counts 3 topics: components, expressions, extended Markdown.
Expressions should be deterministic during the build. Browser-only APIs such
as window and document belong inside a component script rather than the MDX
module body.
Callouts
Callouts highlight information without requiring a custom component:
TIPUse the simplest syntax that works
Choose Markdown for prose, an MDX expression for a small dynamic value, and a component when markup or behavior needs to be reused.
:::tip[Optional title]This content is emphasized as a tip.:::Wiki Links
An inline Wiki Link points to another article while keeping the sentence readable. For example, continue with the Mizuki guide.
A standalone Wiki Link becomes an article card with its available metadata and cover image:

Read [[guide|the Mizuki guide]] for more details.
[[guide]]Math and Chemistry
Inline math uses single dollar signs, while display equations use a pair. The
mhchem extension is also available for chemical notation.
Einstein’s mass-energy relation is .
A chemical reaction can be written as .
Inline: $E = mc^2$
Display: $$\int_0^1 x^2\,dx = \frac{1}{3}$$
Chemistry: $\ce{H2O + CO2 -> H2CO3}$Code Groups
Use a code group when readers may choose between equivalent examples. Each label corresponds to one fenced code block:
export const renderTarget = "page";pnpm build::: code-group labels=[TypeScript, Shell]
```tsexport const renderTarget = "page";```
```bashpnpm build```
:::Images and Captions
Image alt text describes the image for assistive technology. A Markdown title
becomes a visible caption, and an optional w-N% token controls the width.

Valid widths range from w-1% to w-100%. Omit the token when the image should
use the normal responsive width.
Internal and External Links
Relative links and absolute URLs that use the configured site origin are classified as internal. Links to other origins receive the external-link attributes configured by the theme.
- Visit the About page using an absolute site URL.
- Compare it with an external reference.
You can normally use a relative path for internal content; the absolute example above simply demonstrates that both forms receive the same classification.
Writing Portable MDX
The article page, RSS, and Atom share the same content pipeline. Interactive scripts are removed from feeds, but semantic HTML produced by components, callouts, Wiki Links, math, code groups, and images remains readable.
For reliable output:
- Keep the main explanation in Markdown.
- Give images meaningful alt text and components semantic HTML.
- Avoid browser globals in top-level expressions.
- Ensure useful information is visible before client-side JavaScript runs.
- Run
pnpm test,pnpm check, andpnpm buildbefore publishing.
MDX works best as an extension of Markdown—not a replacement for it. Start with plain content, then introduce expressions and components only where they make the article clearer or more reusable.
如果这篇文章对你有帮助,欢迎分享给更多人!
部分信息可能已经过时