|
@@ -1,6 +1,6 @@
|
|
|
import { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
|
|
import { ReactMarkdownOptions } from 'react-markdown/lib/react-markdown';
|
|
|
import slug from 'rehype-slug';
|
|
import slug from 'rehype-slug';
|
|
|
-// import toc, { HtmlElementNode } from 'rehype-toc';
|
|
|
|
|
|
|
+import toc, { HtmlElementNode } from 'rehype-toc';
|
|
|
import breaks from 'remark-breaks';
|
|
import breaks from 'remark-breaks';
|
|
|
import emoji from 'remark-emoji';
|
|
import emoji from 'remark-emoji';
|
|
|
import footnotes from 'remark-footnotes';
|
|
import footnotes from 'remark-footnotes';
|
|
@@ -267,6 +267,33 @@ export const generateViewOptions: ReactMarkdownOptionsGenerator = (config: Rende
|
|
|
return options;
|
|
return options;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+export const generateTocOptions: ReactMarkdownOptionsGenerator = (config: RendererConfig): RendererOptions => {
|
|
|
|
|
+
|
|
|
|
|
+ const options = generateCommonOptions(config);
|
|
|
|
|
+
|
|
|
|
|
+ const { remarkPlugins, rehypePlugins, components } = options;
|
|
|
|
|
+
|
|
|
|
|
+ // add remark plugins
|
|
|
|
|
+ if (remarkPlugins != null) {
|
|
|
|
|
+ remarkPlugins.push(emoji);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // add rehypePlugins
|
|
|
|
|
+ if (rehypePlugins != null) {
|
|
|
|
|
+ rehypePlugins.push([toc, {
|
|
|
|
|
+ headings: ['h1', 'h2', 'h3'],
|
|
|
|
|
+ customizeTOC: () => {
|
|
|
|
|
+ return;
|
|
|
|
|
+ },
|
|
|
|
|
+ }]);
|
|
|
|
|
+ }
|
|
|
|
|
+ // renderer.rehypePlugins.push([autoLinkHeadings, {
|
|
|
|
|
+ // behavior: 'append',
|
|
|
|
|
+ // }]);
|
|
|
|
|
+
|
|
|
|
|
+ return options;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export const generatePreviewOptions: ReactMarkdownOptionsGenerator = (config: RendererConfig): RendererOptions => {
|
|
export const generatePreviewOptions: ReactMarkdownOptionsGenerator = (config: RendererConfig): RendererOptions => {
|
|
|
const options = generateCommonOptions(config);
|
|
const options = generateCommonOptions(config);
|
|
|
|
|
|