File tree 1 file changed +26
-1
lines changed 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';
15
15
16
16
type PartialBy < T , K extends keyof T > = Omit < T , K > & Partial < Pick < T , K > > ;
17
17
18
- export interface UseRemarkOptions {
18
+ export interface UseRemarkSyncOptions {
19
19
remarkParseOptions ?: Partial < RemarkParseOptions > ;
20
20
remarkToRehypeOptions ?: RemarkRehypeOptions ;
21
21
rehypeReactOptions ?: PartialBy <
@@ -24,6 +24,31 @@ export interface UseRemarkOptions {
24
24
> ;
25
25
remarkPlugins ?: PluggableList ;
26
26
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 {
27
52
onError ?: ( err : Error ) => void ;
28
53
}
29
54
You can’t perform that action at this time.
0 commit comments