-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.ts
32 lines (30 loc) · 805 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import rehypeSlug, { type Options as SlugOptions } from 'rehype-slug';
import rehypeAutolinkHeadings, { type Options as AutolinkOptions } from 'rehype-autolink-headings';
import type { Plugin } from 'carta-md';
export * from './default.css?inline';
export interface AnchorExtensionOptions {
/**
* rehype-slug options.
*/
slug?: SlugOptions;
/**
* rehype-autolink-headings options.
*/
autolink?: AutolinkOptions;
}
/**
* Carta anchor plugin. Adds support to render anchor links in header tags.
*/
export const anchor = (options?: AnchorExtensionOptions): Plugin => {
return {
transformers: [
{
execution: 'sync',
type: 'rehype',
transform({ processor }) {
processor.use(rehypeSlug, options?.slug).use(rehypeAutolinkHeadings, options?.autolink);
}
}
]
};
};