跳到主要内容

使用组件

我们提供了一些自定义组件,您可以在文档中使用。

要导入组件,请使用组件描述中的 import 语句。将 import 语句放在文档顶部,主标题之前,以及文档元数据之后。

---
...
hide_title: true
---

{/* PUT IMPORTS HERE */}

# The document heading

以下是我们的自定义组件列表。

Image

扩展图片组件。

导入

import Image from '@site-comps/Image';
pubsrc(必需) 图片源,就像 <img> HTML 标签一样。
pubborder是否在图片周围添加全页面宽度的边框(默认值:false)
pubcenter是否居中图片
pubdesc显示在图片下方的居中描述
pubminwidth一种方便的方式来指定图片的 minWidth
pubwidth一种方便的方式来指定图片的 width
pubmaxwidth一种方便的方式来指定图片的 maxWidth
pubminheight一种方便的方式来指定图片的 minHeight
pubheight一种方便的方式来指定图片的 height
pubmaxheight一种方便的方式来指定图片的 maxHeight
Image 组件示例
<Image center border
maxheight={200}
alt="Goblin enemy presentation"
src="/img/tutorials/course/basic/structures/GoblinEnemy.gif"
desc={<>Goblin image by <a href="https://luizmelo.itch.io/monsters-creatures-fantasy">LuizMelo</a></>}
/>

结果


Goblin enemy presentation
地精图片由 LuizMelo 提供

Columns

将子元素拆分为列。

导入

import Columns from '@site-comps/Columns';
pubcolumns(必需) CSS 列宽(数组),参见下面的示例。
Columns 组件示例
<Columns columns={["8fr", "4fr"]}>
<div>Contents of column 1</div>
<div>Contents of column 2</div>
</Columns>
提示

Columns 组件通常用于并排显示代码及其结果。

您可以使用我放在 .vscode-template 中的预设“coderesult”代码片段。

已知问题

  • 列宽不响应

CustomCodeBlock

为 Markdown 代码块添加附加功能。

导入

import CustomCodeBlock from '@site-comps/CustomCodeBlock';
pubmaxLines超出此行数时,会出现垂直滚动条。
pubresizable用户是否应该能够调整代码块大小

更新日志

  • 移除了 lineNumbers - Docusaurus 现在原生支持 Markdown 代码块中的 showLineNumbers

已知问题

  • 用户可以调整超出代码块高度的大小

GoogleSlides

嵌入 Google 幻灯片演示文稿。

导入

import GoogleSlides from '@site-comps/GoogleSlides';
pubsrc(必需) Google 幻灯片演示文稿的源(在 /embed 之后截断)
pubaspectRatio描述 width : height 比例的数字(默认值:16 / 9
pubdelay自动幻灯片切换之间的间隔(毫秒)
pubautoStart页面加载后是否开始演示文稿(默认值:true
publoop是否循环演示文稿(默认值:true
pubfullWidth是使用页面宽度的 100% (true) 还是 80% (false)(默认值:false

示例

<GoogleSlides
src="https://docs.google.com/presentation/d/e/2PACX-1vTsdQPMXKN90rcz4i515JK-rpUHjHTc5xIjGVtNJS8XSbloMNObHEBUSszvYi9I7tuKBNIdEKNFh1jk/embed"
aspectRatio={960 / 500}
delay={500}
centered
/>

结果



SymbolTable

用于记录符号和属性的表格。

导入

import SymbolTable, { Symbol } from '@site-comps/SymbolTable';

SymbolTable 字段

pubnoTraits是否隐藏最左侧带有符号特性(const、static 等)的列

Symbol 字段

pubname(必需) 符号的名称
pubdesc

符号的描述。您也可以将其指定为子元素

<Symbol name="symbol">
This will be considered a description
</Symbol>
注意

由于 MDX 格式化器的规则,如果您想在 JSX 元素中使用 Markdown 元素,您必须删除缩进,否则它将被识别为代码块。

pubautoLink自动生成链接
publink自定义链接
publinkName当 autoLink=true 时使用的符合 URL 规范的名称

Symbol 特性字段:

pubpub为符号添加“public”特性
pubpriv为符号添加“private”特性
pub保护为符号添加“protected”特性
pubvolatile为符号添加“volatile”特性
pubconst为符号添加“const”特性
pubconstexpr为符号添加“constexpr”特性
pubvirtual为符号添加“virtual”特性
pubstatic为符号添加“static”特性

ClassSummary

导入

import ClassSummary from "@site-comps/ClassSummary";

用法

import ClassSummary				from '@site-comps/ClassSummary';
import SymbolTable, { Symbol } from '@site-comps/SymbolTable';

<ClassSummary name="string" namespaces="std">

### Methods

<SymbolTable>
<Symbol pub autoLink name="contains" desc="Checks if the string contains the given substring or character"/>
<Symbol pub autoLink name="substr" desc="Returns a substring"/>
<Symbol pub autoLink name="empty">
Returns <code>true</code> if the string is empty, otherwise <code>false</code>.
</Symbol>
</SymbolTable>

</ClassSummary>

结果

Class Summary

ClassSummary 字段

pubname(必需) 类的名称
pubnamespaces一个字符串,或一个命名空间列表,例如
namespaces="std"namespaces={["std", "chrono"]}

ProductCard

导入

import ProductCard from '@site-comps/ProductCard';

用法

<ProductCard title="Visual Studio Code" author="Microsoft" img="/img/icons/products/vscode_1_35.svg" rating={9}>
<ProductCard.Desc>
A powerful tool with everything you need, including a code editor
and a compiler that supports the latest C++20 standard.
<ProductCard.Details>
<h3>Pros</h3>
<ul>
<li>All in one</li>
<li>Simple installation and configuration</li>
<li>Access to the latest C++20 standard</li>
<li>The best debugger available</li>
</ul>
<h3>Cons</h3>
<ul>
<li>Relatively big installation size (download ~2 GB, after installation ~7 GB)</li>
<li>Not portable</li>
<li>Windows only</li>
</ul>
</ProductCard.Details>
</ProductCard.Desc>
<ProductCard.Actions>
<a href="https://vscode.js.cn">Product website</a>
</ProductCard.Actions>
</ProductCard>

结果

Product icon

Visual Studio Code (微软)

功能强大的工具,拥有您所需的一切,包括支持最新 C++20 标准的代码编辑器和编译器。

详情

优点

  • 一体化
  • 安装和配置简单
  • 支持最新的 C++20 标准
  • 提供最佳调试器

缺点

  • 安装包相对较大(下载约 2 GB,安装后约 7 GB)
  • 不可移植
  • 仅限 Windows

ProductCard 字段

pubtitle(必需) 类的名称
pubimg(必需) 包含图片 URL 的字符串,或 SVG 元素
pubauthor产品的作者
pubrating产品的评分,用 5 星显示。使用 0 到 10 之间的值。

ProductCard.Desc

它是 ProductCard 的子组件,用于添加产品描述。

ProductCard.Actions

它是 ProductCard 的子组件,用于为产品添加操作内容。

ProductCard.Details

它是 ProductCard 的子组件,用于为产品描述添加详细信息。

注意

ProductCard.Details 仅允许在 ProductCard.Desc 元素内部使用。

ToolCard

导入

import ToolCard from '@site-comps/ToolsSummary';
注意

TODO: 描述

使用组件

我们提供了一些自定义组件,您可以在文档中使用。

要导入组件,请使用组件描述中的 import 语句。将 import 语句放在文档顶部,主标题之前,以及文档元数据之后。

---
...
hide_title: true
---

{/* PUT IMPORTS HERE */}

# The document heading

以下是我们的自定义组件列表。

Image

扩展图片组件。

导入

import Image from '@site-comps/Image';
pubsrc(必需) 图片源,就像 <img> HTML 标签一样。
pubborder是否在图片周围添加全页面宽度的边框(默认值:false)
pubcenter是否居中图片
pubdesc显示在图片下方的居中描述
pubminwidth一种方便的方式来指定图片的 minWidth
pubwidth一种方便的方式来指定图片的 width
pubmaxwidth一种方便的方式来指定图片的 maxWidth
pubminheight一种方便的方式来指定图片的 minHeight
pubheight一种方便的方式来指定图片的 height
pubmaxheight一种方便的方式来指定图片的 maxHeight
Image 组件示例
<Image center border
maxheight={200}
alt="Goblin enemy presentation"
src="/img/tutorials/course/basic/structures/GoblinEnemy.gif"
desc={<>Goblin image by <a href="https://luizmelo.itch.io/monsters-creatures-fantasy">LuizMelo</a></>}
/>

结果


Goblin enemy presentation
地精图片由 LuizMelo 提供

Columns

将子元素拆分为列。

导入

import Columns from '@site-comps/Columns';
pubcolumns(必需) CSS 列宽(数组),参见下面的示例。
Columns 组件示例
<Columns columns={["8fr", "4fr"]}>
<div>Contents of column 1</div>
<div>Contents of column 2</div>
</Columns>
提示

Columns 组件通常用于并排显示代码及其结果。

您可以使用我放在 .vscode-template 中的预设“coderesult”代码片段。

已知问题

  • 列宽不响应

CustomCodeBlock

为 Markdown 代码块添加附加功能。

导入

import CustomCodeBlock from '@site-comps/CustomCodeBlock';
pubmaxLines超出此行数时,会出现垂直滚动条。
pubresizable用户是否应该能够调整代码块大小

更新日志

  • 移除了 lineNumbers - Docusaurus 现在原生支持 Markdown 代码块中的 showLineNumbers

已知问题

  • 用户可以调整超出代码块高度的大小

GoogleSlides

嵌入 Google 幻灯片演示文稿。

导入

import GoogleSlides from '@site-comps/GoogleSlides';
pubsrc(必需) Google 幻灯片演示文稿的源(在 /embed 之后截断)
pubaspectRatio描述 width : height 比例的数字(默认值:16 / 9
pubdelay自动幻灯片切换之间的间隔(毫秒)
pubautoStart页面加载后是否开始演示文稿(默认值:true
publoop是否循环演示文稿(默认值:true
pubfullWidth是使用页面宽度的 100% (true) 还是 80% (false)(默认值:false

示例

<GoogleSlides
src="https://docs.google.com/presentation/d/e/2PACX-1vTsdQPMXKN90rcz4i515JK-rpUHjHTc5xIjGVtNJS8XSbloMNObHEBUSszvYi9I7tuKBNIdEKNFh1jk/embed"
aspectRatio={960 / 500}
delay={500}
centered
/>

结果



SymbolTable

用于记录符号和属性的表格。

导入

import SymbolTable, { Symbol } from '@site-comps/SymbolTable';

SymbolTable 字段

pubnoTraits是否隐藏最左侧带有符号特性(const、static 等)的列

Symbol 字段

pubname(必需) 符号的名称
pubdesc

符号的描述。您也可以将其指定为子元素

<Symbol name="symbol">
This will be considered a description
</Symbol>
注意

由于 MDX 格式化器的规则,如果您想在 JSX 元素中使用 Markdown 元素,您必须删除缩进,否则它将被识别为代码块。

pubautoLink自动生成链接
publink自定义链接
publinkName当 autoLink=true 时使用的符合 URL 规范的名称

Symbol 特性字段:

pubpub为符号添加“public”特性
pubpriv为符号添加“private”特性
pub保护为符号添加“protected”特性
pubvolatile为符号添加“volatile”特性
pubconst为符号添加“const”特性
pubconstexpr为符号添加“constexpr”特性
pubvirtual为符号添加“virtual”特性
pubstatic为符号添加“static”特性

ClassSummary

导入

import ClassSummary from "@site-comps/ClassSummary";

用法

import ClassSummary				from '@site-comps/ClassSummary';
import SymbolTable, { Symbol } from '@site-comps/SymbolTable';

<ClassSummary name="string" namespaces="std">

### Methods

<SymbolTable>
<Symbol pub autoLink name="contains" desc="Checks if the string contains the given substring or character"/>
<Symbol pub autoLink name="substr" desc="Returns a substring"/>
<Symbol pub autoLink name="empty">
Returns <code>true</code> if the string is empty, otherwise <code>false</code>.
</Symbol>
</SymbolTable>

</ClassSummary>

结果

Class Summary

ClassSummary 字段

pubname(必需) 类的名称
pubnamespaces一个字符串,或一个命名空间列表,例如
namespaces="std"namespaces={["std", "chrono"]}

ProductCard

导入

import ProductCard from '@site-comps/ProductCard';

用法

<ProductCard title="Visual Studio Code" author="Microsoft" img="/img/icons/products/vscode_1_35.svg" rating={9}>
<ProductCard.Desc>
A powerful tool with everything you need, including a code editor
and a compiler that supports the latest C++20 standard.
<ProductCard.Details>
<h3>Pros</h3>
<ul>
<li>All in one</li>
<li>Simple installation and configuration</li>
<li>Access to the latest C++20 standard</li>
<li>The best debugger available</li>
</ul>
<h3>Cons</h3>
<ul>
<li>Relatively big installation size (download ~2 GB, after installation ~7 GB)</li>
<li>Not portable</li>
<li>Windows only</li>
</ul>
</ProductCard.Details>
</ProductCard.Desc>
<ProductCard.Actions>
<a href="https://vscode.js.cn">Product website</a>
</ProductCard.Actions>
</ProductCard>

结果

Product icon

Visual Studio Code (微软)

功能强大的工具,拥有您所需的一切,包括支持最新 C++20 标准的代码编辑器和编译器。

详情

优点

  • 一体化
  • 安装和配置简单
  • 支持最新的 C++20 标准
  • 提供最佳调试器

缺点

  • 安装包相对较大(下载约 2 GB,安装后约 7 GB)
  • 不可移植
  • 仅限 Windows

ProductCard 字段

pubtitle(必需) 类的名称
pubimg(必需) 包含图片 URL 的字符串,或 SVG 元素
pubauthor产品的作者
pubrating产品的评分,用 5 星显示。使用 0 到 10 之间的值。

ProductCard.Desc

它是 ProductCard 的子组件,用于添加产品描述。

ProductCard.Actions

它是 ProductCard 的子组件,用于为产品添加操作内容。

ProductCard.Details

它是 ProductCard 的子组件,用于为产品描述添加详细信息。

注意

ProductCard.Details 仅允许在 ProductCard.Desc 元素内部使用。

ToolCard

导入

import ToolCard from '@site-comps/ToolsSummary';
注意

TODO: 描述