@@ -130,7 +130,7 @@ MDX document to parse (`string`, [`Buffer`][buffer] in UTF-8, [`vfile`][vfile],
130
130
or anything that can be given to ` vfile ` ).
131
131
132
132
<details >
133
- <summary >Example </summary >
133
+ <summary >Expand example </summary >
134
134
135
135
``` js
136
136
import {VFile } from ' vfile'
@@ -149,7 +149,7 @@ await compile(new VFile({path: 'path/to/file.mdx', value: '🤭'}))
149
149
List of [ remark plugins] [ remark-plugins ] , presets, and pairs.
150
150
151
151
<details >
152
- <summary >Example </summary >
152
+ <summary >Expand example </summary >
153
153
154
154
``` js
155
155
import remarkFrontmatter from ' remark-frontmatter' // YAML and such.
@@ -168,7 +168,7 @@ await compile(file, {remarkPlugins: [[remarkGfm, {singleTilde: false}], remarkFr
168
168
List of [ rehype plugins] [ rehype-plugins ] , presets, and pairs.
169
169
170
170
<details >
171
- <summary >Example </summary >
171
+ <summary >Expand example </summary >
172
172
173
173
``` js
174
174
import rehypeKatex from ' rehype-katex' // Render math with KaTeX.
@@ -200,7 +200,7 @@ In particular, you might want to pass `clobberPrefix`, `footnoteLabel`, and
200
200
` footnoteBackLabel ` .
201
201
202
202
<details >
203
- <summary >Example </summary >
203
+ <summary >Expand example </summary >
204
204
205
205
``` js
206
206
compile ({value: ' …' }, {remarkRehypeOptions: {clobberPrefix: ' comment-1' }})
@@ -233,7 +233,7 @@ The format cannot be detected if a file is passed without a path or extension:
233
233
So pass a full vfile (with ` path ` ) or an object with a path.
234
234
235
235
<details >
236
- <summary >Example </summary >
236
+ <summary >Expand example </summary >
237
237
238
238
``` js
239
239
compile ({value: ' …' }) // Seen as MDX
@@ -256,7 +256,7 @@ because in those it affects *which* files are “registered”:
256
256
257
257
###### ` options.outputFormat `
258
258
259
- Output format to generate (` 'program ' | 'function-body ' ` , default: ` 'program' ` ).
259
+ Output format to generate (` 'function-body ' | 'program ' ` , default: ` 'program' ` ).
260
260
In most cases ` 'program' ` should be used, as it results in a whole program.
261
261
Internally, [ ` evaluate ` ] [ eval ] uses ` outputFormat: 'function-body' ` to compile
262
262
to code that can be ` eval ` ed with [ ` run ` ] [ run ] .
@@ -275,7 +275,7 @@ statements, but you can support them by setting
275
275
[ ` options.useDynamicImport ` ] [ usedynamicimport ] .
276
276
277
277
<details >
278
- <summary >Example </summary >
278
+ <summary >Expand example </summary >
279
279
280
280
A module ` example.js ` :
281
281
@@ -322,7 +322,7 @@ JavaScript modules, whereas `import()` is available inside function bodies.
322
322
When you turn ` useDynamicImport ` on, you should probably set [ ` options.baseUrl ` ] [ baseurl ] too.
323
323
324
324
<details >
325
- <summary >Example </summary >
325
+ <summary >Expand example </summary >
326
326
327
327
Say we have a couple modules:
328
328
@@ -371,7 +371,7 @@ imports should run relative the path *b*.
371
371
Another example is when evaluating code, whether in Node or a browser.
372
372
373
373
<details >
374
- <summary >Example </summary >
374
+ <summary >Expand example </summary >
375
375
376
376
Say we have a module ` example.js ` :
377
377
@@ -406,7 +406,7 @@ The default can be set to `true` in Node.js through environment variables: set
406
406
` NODE_ENV=development ` .
407
407
408
408
<details >
409
- <summary >Example </summary >
409
+ <summary >Expand example </summary >
410
410
411
411
Say we had some MDX that references a component that can be passed or provided
412
412
at runtime:
@@ -476,7 +476,7 @@ When given, the resulting file will have a `map` field set to a source map (in
476
476
object form).
477
477
478
478
<details >
479
- <summary >Example </summary >
479
+ <summary >Expand example </summary >
480
480
481
481
Assuming ` example.mdx ` from [ § Use] [ use ] exists, then:
482
482
@@ -515,7 +515,7 @@ The provider must export a `useMDXComponents`, which is called to access an
515
515
object of components.
516
516
517
517
<details >
518
- <summary >Example </summary >
518
+ <summary >Expand example </summary >
519
519
520
520
If ` file ` is the contents of ` example.mdx ` from [ § Use] [ use ] , then:
521
521
@@ -556,7 +556,7 @@ The default is to compile JSX away so that the resulting file is immediately
556
556
runnable.
557
557
558
558
<details >
559
- <summary >Example </summary >
559
+ <summary >Expand example </summary >
560
560
561
561
If ` file ` is the contents of ` example.mdx ` from [ § Use] [ use ] , then:
562
562
@@ -598,7 +598,7 @@ The classic runtime compiles to calls such as `h('p')`, the automatic runtime
598
598
compiles to ` import _jsx from '$importSource/jsx-runtime'\n_jsx('p') ` .
599
599
600
600
<details >
601
- <summary >Example </summary >
601
+ <summary >Expand example </summary >
602
602
603
603
If ` file ` is the contents of ` example.mdx ` from [ § Use] [ use ] , then:
604
604
@@ -625,10 +625,10 @@ compile(file, {jsxRuntime: 'classic'})
625
625
626
626
Place to import automatic JSX runtimes from (` string? ` , default: ` 'react' ` ).
627
627
When in the ` automatic ` runtime, this is used to define an import for
628
- ` _Fragment ` , ` _jsx ` , and ` _jsxs ` .
628
+ ` Fragment ` , ` jsx ` , ` jsxs ` , and ` jsxDEV ` .
629
629
630
630
<details >
631
- <summary >Example </summary >
631
+ <summary >Expand example </summary >
632
632
633
633
If ` file ` is the contents of ` example.mdx ` from [ § Use] [ use ] , then:
634
634
@@ -657,7 +657,7 @@ You should most probably define `pragmaFrag` and `pragmaImportSource` too when
657
657
changing this.
658
658
659
659
<details >
660
- <summary >Example </summary >
660
+ <summary >Expand example </summary >
661
661
662
662
If ` file ` is the contents of ` example.mdx ` from [ § Use] [ use ] , then:
663
663
@@ -707,7 +707,7 @@ See `options.pragma` for an example.
707
707
` Promise<VFile> ` — Promise that resolves to the compiled JS as a [ vfile] [ ] .
708
708
709
709
<details >
710
- <summary >Example </summary >
710
+ <summary >Expand example </summary >
711
711
712
712
``` js
713
713
import remarkPresetLintConsistent from ' remark-preset-lint-consistent' // Lint rules to check for consistent markdown.
@@ -749,6 +749,8 @@ Typically, `import` (or `export … from`) do not work here.
749
749
They can be compiled to dynamic ` import() ` by passing
750
750
[ ` options.useDynamicImport ` ] [ usedynamicimport ] .
751
751
752
+ > ☢️ ** Danger** : you likely must set ` development: boolean ` .
753
+
752
754
###### ` file `
753
755
754
756
See [ ` compile ` ] [ compile ] .
@@ -759,25 +761,33 @@ Most options are the same as [`compile`][compile], with the following
759
761
exceptions:
760
762
761
763
* ` providerImportSource ` is replaced by ` useMDXComponents `
762
- * ` jsx* ` and ` pragma* ` options are replaced by ` jsx ` , ` jsxs ` , and ` Fragment `
764
+ * ` jsx* ` and ` pragma* ` options are replaced by ` Fragment ` , ` jsx ` , ` jsxs ` , and
765
+ ` jsxDEV `
763
766
* ` outputFormat ` is set to ` function-body `
764
767
765
768
###### ` options.jsx `
766
769
767
770
###### ` options.jsxs `
768
771
772
+ ###### ` options.jsxDEV `
773
+
769
774
###### ` options.Fragment `
770
775
771
- These three options are required.
776
+ These options are required: ` Fragment ` always, when ` development: true `
777
+ then ` jsx ` and ` jsxs ` , when ` development: false ` then ` jsxDEV ` .
772
778
They come from an automatic JSX runtime that you must import yourself.
773
779
774
780
<details >
775
- <summary >Example </summary >
781
+ <summary >Expand example </summary >
776
782
777
783
``` js
778
784
import * as runtime from ' react/jsx-runtime'
779
785
780
- const {default: Content } = await evaluate (' # hi' , {... runtime, ... otherOptions})
786
+ const {default: Content } = await evaluate (' # hi' , {
787
+ ... runtime,
788
+ ... otherOptions,
789
+ development: false
790
+ })
781
791
```
782
792
783
793
</details >
@@ -787,33 +797,38 @@ const {default: Content} = await evaluate('# hi', {...runtime, ...otherOptions})
787
797
Needed if you want to support a provider.
788
798
789
799
<details >
790
- <summary >Example </summary >
800
+ <summary >Expand example </summary >
791
801
792
802
``` js
793
803
import * as provider from ' @mdx-js/react'
794
804
import * as runtime from ' react/jsx-runtime'
795
805
796
- const {default: Content } = await evaluate (' # hi' , {... provider, ... runtime, ... otherOptions})
806
+ const {default: Content } = await evaluate (' # hi' , {
807
+ ... provider,
808
+ ... runtime,
809
+ ... otherOptions,
810
+ development: false
811
+ })
797
812
```
798
813
799
814
</details >
800
815
801
816
###### Returns
802
817
803
- ` Promise<OMDXModule > ` — Promise that resolves to something that looks a bit like
818
+ ` Promise<MDXModule > ` — Promise that resolves to something that looks a bit like
804
819
a module: an object with a ` default ` field set to the component and anything
805
820
else that was exported from the MDX file available too.
806
821
807
822
<details >
808
- <summary >Example </summary >
823
+ <summary >Expand example </summary >
809
824
810
825
Assuming the contents of ` example.mdx ` from [ § Use] [ use ] was in ` file ` , then:
811
826
812
827
``` js
813
828
import * as runtime from ' react/jsx-runtime'
814
829
import {evaluate } from ' @mdx-js/mdx'
815
830
816
- console .log (await evaluate (file, {... runtime}))
831
+ console .log (await evaluate (file, {... runtime, development : false }))
817
832
```
818
833
819
834
…yields:
@@ -856,8 +871,8 @@ Run MDX compiled as [`options.outputFormat: 'function-body'`][outputformat].
856
871
857
872
###### ` options `
858
873
859
- You can pass ` jsx ` , ` jsxs ` , and ` Fragment ` from an automatic JSX runtime as
860
- ` options ` .
874
+ You can pass ` Fragment ` , ` jsx ` , ` jsxs ` , and ` jsxDEV ` , from an automatic JSX
875
+ runtime as ` options ` .
861
876
You can also pass ` useMDXComponents ` from a provider in options if the MDX is
862
877
compiled with ` options.providerImportSource: '#' ` (the exact value of this
863
878
compile option doesn’t matter).
@@ -868,14 +883,17 @@ All other options have to be passed to `compile` instead.
868
883
` Promise<MDXModule> ` — See ` evaluate `
869
884
870
885
<details >
871
- <summary >Example </summary >
886
+ <summary >Expand example </summary >
872
887
873
888
On the server:
874
889
875
890
``` js
876
891
import {compile } from ' @mdx-js/mdx'
877
892
878
- const code = String (await compile (' # hi' , {outputFormat: ' function-body' }))
893
+ const code = String (await compile (' # hi' , {
894
+ outputFormat: ' function-body' ,
895
+ development: false
896
+ }))
879
897
// To do: send `code` to the client somehow.
880
898
```
881
899
@@ -934,15 +952,15 @@ what unified does: please read through the [`unifiedjs/unified`][unified] readme
934
952
know about unified: [ ` core.js#L65 ` ] [ core ] .
935
953
The processor goes through these steps:
936
954
937
- 1 . Parse MDX (serialized markdown with embedded JSX, ESM, and expressions)
955
+ 1 . parse MDX (serialized markdown with embedded JSX, ESM, and expressions)
938
956
to mdast (markdown syntax tree)
939
- 2 . Transform through remark (markdown ecosystem)
940
- 3 . Transform mdast to hast (HTML syntax tree)
941
- 4 . Transform through rehype (HTML ecosystem)
942
- 5 . Transform hast to esast (JS syntax tree)
943
- 6 . Do the work needed to get a component
944
- 7 . Transform through recma (JS ecosystem)
945
- 8 . Serialize esast as JavaScript
957
+ 2 . transform through remark (markdown ecosystem)
958
+ 3 . transform mdast to hast (HTML syntax tree)
959
+ 4 . transform through rehype (HTML ecosystem)
960
+ 5 . transform hast to esast (JS syntax tree)
961
+ 6 . do the work needed to get a component
962
+ 7 . transform through recma (JS ecosystem)
963
+ 8 . serialize esast as JavaScript
946
964
947
965
The * input* is MDX (serialized markdown with embedded JSX, ESM, and
948
966
expressions).
1 commit comments
vercel[bot] commentedon Feb 9, 2023
Successfully deployed to the following URLs:
mdx – ./
mdx-mdx.vercel.app
mdxjs.com
mdx-git-main-mdx.vercel.app
v2.mdxjs.com