File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import rehypeReact, { Options as RehypeReactOptions } from 'rehype-react';
1515
1616type PartialBy < T , K extends keyof T > = Omit < T , K > & Partial < Pick < T , K > > ;
1717
18- export interface UseRemarkOptions {
18+ export interface UseRemarkSyncOptions {
1919 remarkParseOptions ?: Partial < RemarkParseOptions > ;
2020 remarkToRehypeOptions ?: RemarkRehypeOptions ;
2121 rehypeReactOptions ?: PartialBy <
@@ -24,6 +24,31 @@ export interface UseRemarkOptions {
2424 > ;
2525 remarkPlugins ?: PluggableList ;
2626 rehypePlugins ?: PluggableList ;
27+ }
28+
29+ export const useRemarkSync = (
30+ source : string ,
31+ {
32+ remarkParseOptions,
33+ remarkToRehypeOptions,
34+ rehypeReactOptions,
35+ remarkPlugins = [ ] ,
36+ rehypePlugins = [ ] ,
37+ } : UseRemarkOptions = { }
38+ ) : ReactElement =>
39+ unified ( )
40+ . use ( remarkParse , remarkParseOptions )
41+ . use ( remarkPlugins )
42+ . use ( remarkToRehype , remarkToRehypeOptions )
43+ . use ( rehypePlugins )
44+ . use ( rehypeReact , {
45+ createElement,
46+ Fragment,
47+ ...rehypeReactOptions ,
48+ } as RehypeReactOptions < typeof createElement > )
49+ . processSync ( source ) . result as ReactElement ;
50+
51+ export interface UseRemarkOptions extends UseRemarkSyncOptions {
2752 onError ?: ( err : Error ) => void ;
2853}
2954
You can’t perform that action at this time.
0 commit comments