MDX 的一个优点是你可以编写 markdown 并指定要使用的组件而不是 HTML 元素。 下表列出了那些可以被覆盖的 HTML 元素、所需的 markdown 以及正常的 JSX 等效项。但是,以 a 的第一行为例,你可以通过执行以下操作将该超链接替换为 <FancyLink>:
¥A great thing about MDX is that you can write markdown and specify a component to be used instead of an HTML element. The following table lists those HTML elements that can be overwritten, the needed markdown, and what the normal JSX equivalent would be. But, taking the first row for a as an example, you can replace that hyperlink with <FancyLink> by doing:
TypeScript
importReadmefrom'./readme.md'// Assumes an integration is used to compile MDX -> JS.import {FancyLink} from'./components/fancy-link.js'
<Readmecomponents={{a: FancyLink}} />
¥The components you can overwrite use their standard HTML names. Normally, in markdown, those names are: a, blockquote, br, code, em, h1, h2, h3, h4, h5, h6, hr, img, li, ol, p, pre, strong, and ul. With remark-gfm (see guide), you can also use: del, input, section, sup, table, tbody, td, th, thead, and tr. Other remark plugins that add support for new constructs and advertise that they work with rehype, will also work with MDX.