MDX
MDX 是一种 Markdown 的扩展语法,允许在 Markdown 中使用 JSX 语法,使用方式可以参考 rspress MDX。
目录
rspress 组件doom 组件OverviewCalloutsCalloutDirectiveExternalSiteExternalSiteLinkAcpApisOverview 与 ExternalApisOverviewTermpropsTermsTablepropsJsonViewer自定义组件复用rspress 组件
rspress 主题提供的内置组件大部分已调整为全局组件,可以在 .mdx 文件中无需导入直接使用,包括:
BadgePackageManagerTabsStepsTab/TabsToc
其他不常用的组件可以通过 rspress/theme 导入使用,例如:
doom 组件
doom 提供了一些全局组件来辅助文档编写,不需要导入即可直接使用,目前包括:
Overview
文档概览组件,用于展示文档目录
Callouts
同 Callouts Markdown 扩展功能,源码标注组件
- Required for the processes that run in the
virt-launcherpod. - Number of virtual CPUs requested by the virtual machine.
- Number of virtual graphics cards requested by the virtual machine.
- Additional memory overhead:
- If your environment includes a Single Root I/O Virtualization (SR-IOV) network device or a Graphics Processing Unit (GPU), allocate 1 GiB additional memory overhead for each device.
- If Secure Encrypted Virtualization (SEV) is enabled, add 256 MiB.
- If Trusted Platform Module (TPM) is enabled, add 53 MiB.
Callout
同 Callout Markdown 扩展功能,代码块外独立标注组件
1 A- x details of x
- y details of y
Directive
有时,由于嵌套缩进,自定义容器语法可能失效,可以使用 Directive 组件代替
-
多语言文档(
doc/en)的目录结构需要与doc/zh目录下的文档完全一致,保证多语言文档的链接除了语言标识外完全相同。注意如果是使用自动化翻译工具进行翻译,则无需关心该问题,自动化翻译工具会自动根据
doc/zh生成目标语言文档的目录结构。
ExternalSite
引用外部站点组件
ExternalSiteLink
引用外部站点链接组件
Content在 mdx 中 <ExternalSiteLink name="connectors" href="link" children="Content" /> 与下面的内容含义不同
如果不希望文本渲染在 p 元素内,可以像上面的示例一样使用 children 属性传递
AcpApisOverview 与 ExternalApisOverview
引用外部站点 API 概览组件
Term
术语组件,纯文本,动态挂载注入
props
name: 内置术语名称,参考动态挂载配置文件textCase: 文本大小写转换,可选值为lower,upper,capitalize
TermsTable
内置术语列表展示组件
props
terms:NormalizedTermItem[],可选,自定义术语列表,方便内部文档渲染自定义术语时复用
JsonViewer
自定义组件复用
根据约定,我们可以将需要复用的内容抽取到 shared 目录中,然后在需要的地方引入即可,比如:
如果需要使用更多 runtime 相关的 API,可以使用 .jsx/.tsx 实现组件,然后在 .mdx 文件中引入使用。
注意:目前 .mdx 导出的组件不支持 props 传参,参考此 issue,因此需要传递 props 的场景请使用 .jsx/.tsx 组件进行开发