跳到主要内容
版本:Canary 🚧

Markdown 特性

Docusaurus 使用**Markdown**作为其主要的内容创作格式。

学习 Markdown

Docusaurus uses modern tooling to help you create interactive documentation.

The MDX compiler transforms Markdown files to React components, and allows you to use JSX in your Markdown content. This enables you to easily interleave React components within your content, and create delightful learning experiences.

Use the MDX Playground

The MDX playground is your new best friend!

It is a very helpful debugging tool that shows how the MDX compiler transforms Markdown to React.

Options: select the right format (MDX or CommonMark) and the following plugins Docusaurus uses: remark-gfm, remark-directive, rehype-raw.

MDX vs. CommonMark

Docusaurus 使用 mdx 编译器将.md.mdx文件编译为 React 组件,但是语法可以根据您的设置进行不同的解释。

MDX 编译器支持2 种格式:

默认情况下,Docusaurus v3 使用 MDX 格式的所有文件**(包括.md文件)由于历史原因。

使用siteConfig.markdown.format设置或format: md前面的内容可以选择加入 CommonMark

如何使用 CommonMark

如果您打算使用 CommonMark,我们建议使用siteConfig.markdown.format: 'detect'设置。将根据文件扩展名自动选择适当的格式:

  • .md 文件将使用 CommonMark 格式
  • .mdx 文件将使用 MDX 格式

标准特性

Markdown 是一种语法,它使您能够以可读的语法编写格式化的内容。

### My Doc Section

Hello world message with some **bold** text, some _italic_ text, and a [link](/)

![img alt](/img/docusaurus.png)
http://localhost:3000

My Doc Section

Hello world message with some bold text, some italic text and a link

img alt

Markdown是声明性的

Some may assume a 1-1 correlation between Markdown and HTML, e.g., ![Preview](/img/docusaurus.png) will always become <img src="/img/docusaurus.png" alt="Preview" />, as-is. However, that is not the case.

The Markdown syntax ![message](url) only declaratively tells Docusaurus that an image needs to be inserted here, but we may do other things like transforming a file path to URL path, so the generated markup may differ from the output of other Markdown renderers, or a naïve hand-transcription to the equivalent JSX/HTML code.

In general, you should only assume the semantics of the markup (``` fences become code blocks; > becomes quotes, etc.), but not the actual compiled output.

页眉

正面内容用于向 Markdown 文件添加元数据。所有内容插件都有自己的前内容模式,并使用前内容来丰富从内容或其他配置推断的默认元数据。

在文件的最顶部提供了前面的内容,用三个破折号---括起来。内容解析为YAML

---
title: My Doc Title
more_data:
- Can be provided
- as: objects
or: arrays
---
信息

每个官方插件的 API 文档都列出了支持的属性:

Quotes

Markdown quotes 风格优美:

> Easy to maintain open source documentation websites.
>
> — Docusaurus
http://localhost:3000

Easy to maintain open source documentation websites.

— Docusaurus

Details

Markdown can embed HTML elements, and details HTML elements are beautifully styled:

### Details element example

<details>
<summary>Toggle me!</summary>
<div>
<div>This is the detailed content</div>
<br/>
<details>
<summary>
Nested toggle! Some surprise inside...
</summary>
<div>😲😲😲😲😲</div>
</details>
</div>
</details>
http://localhost:3000

Details element example

Toggle me!
This is the detailed content

Nested toggle! Some surprise inside...

😲😲😲😲😲