Markdown Features
Docusaurus uses GitHub Flavored Markdown (GFM). Find out more about Docusaurus-specific fields when writing Markdown.
Markdown 标题
文档
文档使用以下 markdown 协议头字段, 它们由两侧的行 ---
括起来:
id
: A unique document id. If this field is not present, the document's id
will default to its file name (without the extension).
title
: The title of your document. If this field is not present, the document's title
will default to its id
.
hide_title
: Whether to hide the title at the top of the doc.
sidebar_label
: The text shown in the document sidebar and in the next/previous button for this document. If this field is not present, the document's sidebar_label
will default to its title
.
例如:
---
id: doc1
title: My Document
sidebar_label: Document
---
经过版本控制的文档在被复制时会更改其 id 这样才能包含版本号。 新的 id
为 version-${version}-${id}
, 其中 ${version}
是该文档的版本号, $ {id}
是原始的 id
。 此外,版本文档可得到original_id
文件,使用原版的文件id。
例如:
---
id: version-1.0.0-doc1
title: My Document
sidebar_label: Document
original_id: doc1
---
custom_edit_url
: The URL for editing this document. If this field is not present, the document's edit URL will fall back to editUrl
from optional fields of siteConfig.js
. See siteConfig.js docs for more information.
例如:
---
id: doc-markdown
title: Markdown Features
custom_edit_url: https://github.com/facebook/docusaurus/edit/master/docs/api-doc-markdown.md
---
博客文章
Blog posts use the following markdown header fields that are enclosed by a line ---
on either side:
tittle
: 此博客文章的标题。
author
: The author of this blog post. If this field is omitted, no author name will be shown.
authorURL
: A page to link to when a site user clicks the author's name. If this field is omitted, the author's name will not link to anything.
authorFBID
: 作者的 Facebook(脸书) id, 仅用于让作者的个人资料图片显示在博客文章中。 如果省略此字段, 则不会显示该作者的图片在这篇文章中。
例如:
---
tittle: My First Blog Post
author: Frank Li
authorURL: http://twitter.com/franchementli
authorFBID: 100002976521003
---
更多功能
Docusaurus 在markdown中编写文档时支持一些额外的功能。
链接到其他文档
You can use relative URLs to other documentation files which will automatically get converted to the corresponding HTML links when they get rendered.
例如:
[This links to another document](other-document.md)
这样, markdown将把它自动转换成指向 /docs/other-document.html
的链接(或适当翻译/版本控制链接) 。
This can help when you want to navigate through docs on GitHub since the links there will be functional links to other documents (still on GitHub), but the documents will have the correct HTML links when they get rendered.
链接到图像和其它资源
Static assets can be linked to in the same way that documents are, using relative URLs. 在文档和博客中使用的静态资产应分别进入 docs/assets
和 website/blog/assets
。 Markdown 被转换成正确的链接路径, 这样这些路径就能为所有语言和版本的文档所用。
例如:
![alt-text](assets/doc-image.png)
生成目录
You can make an auto-generated list of links, which can be useful as a table of contents for API docs.
In your markdown file, insert a line with the text ``. 使用 h3
为标题在代码块里为每个函数编写文档。 These will be found by Docusaurus and a list of links to these sections will be inserted at the text <AUTOGENERATED_TABLE_OF_CONTENTS>
.
例如:
### `docusaurus.function(a, b)`
Text describing my function
### `docdoc(file)`
Text describing my function
这将会把页面带去这些功能的目录:
- `docusaurus.function(a, b)`
- `docdoc(file)`
每个函数将会把链接带到页面相对应的部分。
Language-specific Code Tabs
Display code in multiple programming languages using code tabs. First, mark the start and end of a code tabs group, by using <!-- DOCUSAURUS_CODE_TABS -->
and <!-- END_DOCUSAURUS_CODE_TABS -->
respectively in your markdown. Then start each tab with <!--[TAB_TITLE]-->
.
Adding the following code to your Markdown file:
produces this:
console.log('Hello, world!');
print('Hello, world!')
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
program HelloWorld;
begin
WriteLn('Hello, world!');
end.
Syntax Highlighting
Syntax highlighting is enabled by default on fenced code blocks. The language should be detected automatically, but you can sometimes get better results by specifying the language. You can do so using an info string, following the three opening backticks. The following JavaScript example...
```js
ReactDOM.render(<h1>Hello, world!</h1>, document.getElementById('root'));
```
...would be rendered with syntax highlighting like so:
ReactDOM.render(<h1>Hello, world!</h1>, document.getElementById('root'));
Highlighting is provided by Highlight.js using the theme specified in your siteConfig.js
file as part of the highlight
key:
{
...
highlight: {
theme: 'default'
}
...
}
You can find the full list of supported themes in the Highlight.js styles
directory.
Registering additional languages
While Highlight.js provides support for many popular languages out of the box, you may find the need to register additional language support. For these cases, we provide an escape valve by exposing the hljs
constant as part of the highlight
config key. This in turn allows you to call registerLanguage
:
{
...
highlight: {
theme: 'default',
hljs: function(hljs) {
hljs.registerLanguage('galacticbasic', function(hljs) {
// ...
});
}
}
}
Using Prism as additional syntax highlighter
You can also opt to use Prism to syntax highlight certain languages available in the list here. Include those languages in usePrism
field in your siteConfig.js
例如:
// siteConfig.js
usePrism: ['jsx']
Notice that the code block below uses JSX syntax highlighting from Prism.
class Example extends React.Component {
render() {
return (
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>Docusaurus</Text>
<Button
title="Click me"
onPress={() => this.props.navigation.push('Docusaurus')}
/>
</View>
);
}
}
Adding Copy Code Buttons
Docusaurus allows for adding buttons to copy the code within fenced code blocks. Please follow the instructions here to add "Copy" buttons to your code blocks.