Skip to content

Commit d3a7e04

Browse files
committed
refactor
1 parent 7dab414 commit d3a7e04

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

rescript.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
"error": "+8"
3030
},
3131
"suffix": ".mjs",
32-
"bsc-flags": [
33-
"-bs-g"
34-
],
3532
"gentypeconfig": {
3633
"language": "untyped",
3734
"shims": [],

src/ApiDocs.res

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,11 @@ type params = {slug: array<string>}
184184
type props = result<api, string>
185185

186186
module MarkdownStylize = {
187-
external asMarkdownH2: 'a => Markdown.H2.props<string, React.element> => React.element =
188-
"%identity"
189187
@react.component
190-
let make = (~content, ~rehypePlugins: option<array<MdxRemote.mdxPlugin>>=?) => {
188+
let make = (~content, ~rehypePlugins) => {
191189
let components = {
192190
...MarkdownComponents.default,
193-
h2: MarkdownComponents.default.h3->asMarkdownH2,
191+
h2: MarkdownComponents.default.h3->Obj.magic,
194192
}
195193
<ReactMarkdown components={components} ?rehypePlugins> content </ReactMarkdown>
196194
}
@@ -203,19 +201,18 @@ module DeprecatedMessage = {
203201
| Some(content) =>
204202
<Markdown.Warn>
205203
<h4 className={"hl-4 mb-2"}> {"Deprecated"->React.string} </h4>
206-
<MarkdownStylize content />
204+
<MarkdownStylize content rehypePlugins=None />
207205
</Markdown.Warn>
208206
| None => React.null
209207
}
210208
}
211209
}
212210

213211
module DocstringsStylize = {
214-
external asMdxPlugin: 'a => MdxRemote.mdxPlugin = "%identity"
215212
@react.component
216213
let make = (~docstrings, ~slugPrefix) => {
217-
let options = {"prefix": slugPrefix ++ "-"}->asMdxPlugin
218-
let rehypePlugins = [[MdxRemote.rehypeSlug, options]->asMdxPlugin]
214+
let rehypePlugins =
215+
[Rehype.WithOptions([Plugin(Rehype.slug), SlugOption({prefix: slugPrefix ++ "-"})])]->Some
219216

220217
let content = switch docstrings->Js.Array2.length > 1 {
221218
| true => docstrings->Js.Array2.sliceFrom(1)
@@ -389,8 +386,6 @@ module Data = {
389386
}
390387
}
391388

392-
external asTocTree: Js.Json.t => node = "%identity"
393-
394389
let processStaticProps = (~slug: array<string>, ~version: string) => {
395390
let moduleName = slug->Belt.Array.getExn(0)
396391
let content = Data.getVersion(~version, ~moduleName)
@@ -472,7 +467,7 @@ let processStaticProps = (~slug: array<string>, ~version: string) => {
472467
let toctree = tree->Js.Dict.get(moduleName)
473468

474469
switch toctree {
475-
| Some(toctree) => Ok({module_, toctree: toctree->asTocTree})
470+
| Some(toctree) => Ok({module_, toctree: (Obj.magic(toctree): node)})
476471
| None => Error(`Failed to find toctree to ${modulePath}`)
477472
}
478473
| _ => Error(`Failed to find module ${modulePath}`)

src/bindings/MdxRemote.res

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
type output = {frontmatter: Js.Json.t, compiledSource: string, scope: Js.Json.t}
22

3-
type mdxPlugin
4-
53
type mdxOptions = {
6-
remarkPlugins?: array<mdxPlugin>,
7-
rehypePlugins?: array<mdxPlugin>,
4+
remarkPlugins?: array<Remark.remarkPlugin>,
5+
rehypePlugins?: array<Rehype.rehypePlugin>,
86
}
97

108
type serializeOptions = {
@@ -15,14 +13,13 @@ type serializeOptions = {
1513
@module("next-mdx-remote/serialize")
1614
external serialize: (string, serializeOptions) => promise<output> = "serialize"
1715

18-
@module("remark-comment") external remarkComment: mdxPlugin = "default"
19-
@module("remark-gfm") external remarkGfm: mdxPlugin = "default"
20-
@module("remark-frontmatter") external remarkFrontmatter: mdxPlugin = "default"
21-
@module("rehype-slug") external rehypeSlug: mdxPlugin = "default"
22-
2316
let defaultMdxOptions = {
24-
remarkPlugins: [remarkComment, remarkGfm, remarkFrontmatter],
25-
rehypePlugins: [rehypeSlug],
17+
rehypePlugins: [Rehype.Plugin(Rehype.slug)],
18+
remarkPlugins: [
19+
Remark.Plugin(Remark.comment),
20+
Remark.Plugin(Remark.gfm),
21+
Remark.Plugin(Remark.frontmatter),
22+
],
2623
}
2724

2825
@react.component @module("next-mdx-remote")

src/bindings/ReactMarkdown.res

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
external make: (
33
~children: string,
44
~components: MarkdownComponents.t=?,
5-
~rehypePlugins: array<MdxRemote.mdxPlugin>=?,
6-
) => React.element = "default"
5+
~rehypePlugins: array<Rehype.rehypePlugin>=?,
6+
) => // ~rehypePlugins: array<MdxRemote.mdxPlugin>=?,
7+
React.element = "default"

src/bindings/Rehype.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type io
2+
type processor
3+
type plugin = processor => io
4+
5+
@unboxed
6+
type pluginOrOption =
7+
| Plugin(plugin)
8+
| SlugOption({prefix: string})
9+
10+
@unboxed
11+
type rec rehypePlugin =
12+
| Plugin(processor => io)
13+
| WithOptions(array<pluginOrOption>)
14+
15+
@module("rehype-slug") external slug: plugin = "default"

src/bindings/Remark.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type io
2+
type processor
3+
type plugin = processor => io
4+
5+
@unboxed
6+
type pluginOrOption = Plugin(plugin)
7+
8+
@unboxed
9+
type rec remarkPlugin =
10+
| Plugin(processor => io)
11+
| WithOptions(array<pluginOrOption>)
12+
13+
@module("remark-comment") external comment: plugin = "default"
14+
@module("remark-gfm") external gfm: plugin = "default"
15+
@module("remark-frontmatter") external frontmatter: plugin = "default"

0 commit comments

Comments
 (0)