File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,33 @@ import { Options as RemarkRehypeOptions } from 'mdast-util-to-hast';
13
13
import remarkToRehype from 'remark-rehype' ;
14
14
import rehypeReact , { Options as RehypeReactOptions } from 'rehype-react' ;
15
15
16
- export interface UseRemarkOptions {
16
+ export interface UseRemarkSyncOptions {
17
17
remarkParseOptions ?: Partial < RemarkParseOptions > ;
18
18
remarkToRehypeOptions ?: RemarkRehypeOptions ;
19
19
rehypeReactOptions ?: Partial < RehypeReactOptions < typeof createElement > > ;
20
20
remarkPlugins ?: PluggableList ;
21
21
rehypePlugins ?: PluggableList ;
22
+ }
23
+
24
+ export const useRemarkSync = (
25
+ source : string ,
26
+ {
27
+ remarkParseOptions,
28
+ remarkToRehypeOptions,
29
+ rehypeReactOptions,
30
+ remarkPlugins = [ ] ,
31
+ rehypePlugins = [ ] ,
32
+ } : UseRemarkOptions = { }
33
+ ) : ReactElement =>
34
+ unified ( )
35
+ . use ( remarkParse , remarkParseOptions )
36
+ . use ( remarkPlugins )
37
+ . use ( remarkToRehype , remarkToRehypeOptions )
38
+ . use ( rehypePlugins )
39
+ . use ( rehypeReact , { createElement, Fragment, ...rehypeReactOptions } )
40
+ . processSync ( source ) . result as ReactElement ;
41
+
42
+ export interface UseRemarkOptions extends UseRemarkSyncOptions {
22
43
onError ?: ( err : Error ) => void ;
23
44
}
24
45
You can’t perform that action at this time.
0 commit comments