File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import { evaluate } from 'next-mdx-remote-client/rsc' ;
12import { serialize as baseSerialize } from 'next-mdx-remote-client/serialize' ;
23import rehypeKatex from 'rehype-katex' ;
34import remarkGfm from 'remark-gfm' ;
@@ -52,3 +53,49 @@ export const serialize = async ({
5253 throw error ;
5354 }
5455} ;
56+
57+ export const rscSerialize = async ( {
58+ source,
59+ mdxOptions,
60+ scope,
61+ parseFrontmatter = true ,
62+ } : {
63+ source : string ;
64+ mdxOptions ?: SerializeOptions [ 'mdxOptions' ] ;
65+ scope ?: SerializeOptions [ 'scope' ] ;
66+ parseFrontmatter ?: SerializeOptions [ 'parseFrontmatter' ] ;
67+ } ) => {
68+ try {
69+ return await evaluate ( {
70+ source,
71+ options : {
72+ mdxOptions : {
73+ ...mdxOptions ,
74+ remarkPlugins : [
75+ remarkGfm ,
76+ remarkSmartypants ,
77+ remarkMath ,
78+ ...( mdxOptions ?. remarkPlugins || [ ] ) ,
79+ ] ,
80+ rehypePlugins : [
81+ rehypeKatex ,
82+ [
83+ rehypeSyntaxHighlighting ,
84+ {
85+ ignoreMissing : true ,
86+ } ,
87+ ] ,
88+ ...( mdxOptions ?. rehypePlugins || [ ] ) ,
89+ ] ,
90+ format : mdxOptions ?. format || 'mdx' ,
91+ } ,
92+ scope,
93+ parseFrontmatter,
94+ } ,
95+ } ) ;
96+ } catch ( error ) {
97+ console . error ( `Error occurred while serializing MDX: ${ error } ` ) ;
98+
99+ throw error ;
100+ }
101+ } ;
You can’t perform that action at this time.
0 commit comments