AriaDocs provides built-in rehype and remark plugins for extending MDX processing. Import them from the @ariadocs/react/plugins sub-path.
| Plugin | Description |
|---|---|
remarkGfm | GitHub Flavored Markdown support |
rehypePrism | Syntax highlighting with Prism.js |
rehypeSlug | Add IDs to headings |
rehypeAutolinkHeadings | Add anchor links to headings |
rehypeCodeTitles | Add titles to code blocks |
rehypeCodeRaw | Inject raw code string into <pre> for copying |
import {
remarkGfm,
rehypePrism,
rehypeSlug,
rehypeAutolinkHeadings,
rehypeCodeTitles,
rehypeCodeRaw,
} from "@ariadocs/react/plugins";
remarkGfmEnables GitHub Flavored Markdown features:
import { createDocs } from "@ariadocs/react";
import { remarkGfm } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
remarkPlugins: [remarkGfm],
});
| Column 1 | Column 2 |
| -------- | -------- |
| Cell 1 | Cell 2 |
~~Strikethrough text~~
- [x] Completed task
- [ ] Incomplete task
https://autolink.example.com
rehypePrismSyntax highlighting for code blocks using Prism.js.
import { createDocs } from "@ariadocs/react";
import { rehypePrism } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
rehypePlugins: [rehypePrism],
});
Import the syntax highlighting CSS:
import "@ariadocs/react/syntax.css";
Prism supports many languages including:
```tsx
const greeting: string = "Hello, World!";
console.log(greeting);
```
---
## `rehypeSlug`
Adds unique IDs to all headings based on their text content.
### Usage
```tsx
import { rehypeSlug } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
rehypePlugins: [rehypeSlug],
});
# Getting Started
## Installation
Becomes:
<h1 id="getting-started">Getting Started</h1>
<h2 id="installation">Installation</h2>
rehypeAutolinkHeadingsAdds anchor links to headings for easy sharing and navigation.
import { rehypeSlug, rehypeAutolinkHeadings } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings],
});
Note: Use with rehypeSlug to ensure headings have IDs.
Headings become clickable links:
<h1 id="getting-started">
<a href="#getting-started">Getting Started</a>
</h1>
rehypeCodeTitlesAdds titles/filenames to code blocks.
import { rehypeCodeTitles } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
rehypePlugins: [rehypeCodeTitles],
});
```tsx:app.tsx
export default function App() {
return <div>Hello</div>;
}
```
### Result
The code block will have a title "app.tsx" displayed above it.
---
## `rehypeCodeRaw`
Injects the raw code string into `<pre>` elements, useful for building copy buttons.
### Usage
```tsx
import { rehypeCodeRaw } from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
rehypePlugins: [rehypeCodeRaw],
});
The raw code is added as a data-raw attribute on <pre> elements:
<pre data-raw="const greeting = 'Hello';">
<code>...</code>
</pre>
Combine plugins for the best experience:
import { createDocs } from "@ariadocs/react";
import {
remarkGfm,
rehypePrism,
rehypeSlug,
rehypeAutolinkHeadings,
rehypeCodeTitles,
} from "@ariadocs/react/plugins";
const docs = createDocs({
contentDir: "contents/docs",
remarkPlugins: [remarkGfm],
rehypePlugins: [
rehypeSlug,
rehypeAutolinkHeadings,
rehypeCodeTitles,
rehypePrism,
],
});
The order of rehype plugins matters:
rehypeSlug - Add IDs firstrehypeAutolinkHeadings - Then add links to those IDsrehypeCodeTitles - Process code blocksrehypePrism - Apply syntax highlighting lastPlugins are available from a dedicated sub-path for tree-shaking:
import { remarkGfm, rehypePrism } from "@ariadocs/react/plugins";