1
1
[ ![ Build Status] ( https://img.shields.io/endpoint?url=https%3A%2F%2Fci.ocamllabs.io%2Fbadge%2Frealworldocaml%2Fmdx%2Fmain&logo=ocaml )] ( https://ci.ocamllabs.io/github/realworldocaml/mdx )
2
2
3
- ## mdx -- executable code blocks inside documentation
3
+ ## MDX
4
4
5
- ` mdx ` allows to execute code blocks inside markdown and mli documentation
5
+ MDX allows to execute code blocks inside markdown and mli documentation
6
6
to help keeping them up to date.
7
7
8
8
Use the
@@ -178,7 +178,7 @@ with a padding of 3:
178
178
10
179
179
```
180
180
181
- ` ocaml-mdx ` will also consider exit codes when the syntax ` [<exit code>] ` is used:
181
+ MDX will also consider exit codes when the syntax ` [<exit code>] ` is used:
182
182
183
183
```sh
184
184
$ exit 1
@@ -190,7 +190,7 @@ of success).
190
190
191
191
#### OCaml Code
192
192
193
- ` ocaml-mdx ` interprets OCaml fragments. It understands _ normal_ code fragments and
193
+ MDX interprets OCaml fragments. It understands _ normal_ code fragments and
194
194
_ toplevel_ code fragments (starting with a ` # ` sign and optionally ending with
195
195
` ;; ` ). Arbitrary whitespace padding is supported, at long as it stays
196
196
consistent within a code block.
@@ -211,7 +211,8 @@ Here is an examples of toplevel OCaml code:
211
211
```
212
212
213
213
### File sync
214
- ` mdx ` is also capable of including content from files in fenced code blocks
214
+
215
+ MDX is also capable of including content from files in fenced code blocks
215
216
using the label ` file ` . OCaml files can be sliced using named blocks:
216
217
217
218
``` ocaml
@@ -234,38 +235,6 @@ Non-OCaml files can also be read and included in a block:
234
235
```
235
236
However, part splitting is only supported for OCaml files.
236
237
237
- ### Pre-processing
238
-
239
- ` ocaml-mdx pp ` allows to transform a markdown file into a valid
240
- OCaml file, which can be passed to OCaml using the ` -pp `
241
- option.
242
-
243
- For instance, given the following ` file.md ` document:
244
-
245
- ```ocaml
246
- # print_endline "42"
247
- 42
248
- ```
249
-
250
- Can be compiled and executed using:
251
-
252
- ``` sh
253
- $ ocamlc -pp ' ocaml-mdx pp' -impl file.md -o file.exe
254
- $ ./file.exe
255
- 42
256
- ```
257
-
258
- This can be automated using ` dune ` :
259
-
260
- ```
261
- (rule
262
- ((targets (file.ml))
263
- (deps (file.md))
264
- (action (with-stdout-to ${@} (run ocaml-mdx pp ${<})))))
265
-
266
- (executable ((name file)))
267
- ```
268
-
269
238
### Tests
270
239
271
240
#### Cram Tests
@@ -294,51 +263,6 @@ To execute OCaml code and toplevel fragments, uses `ocaml-mdx test <file.md>`.
294
263
If the output is not consistent with what is expected
295
264
` <file.md>.corrected ` is generated.
296
265
297
- #### Integration with Dune
298
-
299
- To test that the code blocks of ` file.md ` stay consistent, one can use
300
- dune's ` mdx ` stanza:
301
-
302
- ```
303
- (mdx
304
- (files file.md))
305
- ```
306
-
307
- This allows to test the consistency of a markdown file using the normal dev
308
- workflow:
309
-
310
- ```
311
- $ dune runtest
312
- ```
313
-
314
- will display a diff of the output if something has changed. For instance:
315
-
316
- ```
317
- $ dune runtest
318
- ------ file.md
319
- ++++++ file.md.corrected
320
- File "file.md", line 23, characters 0-1:
321
- |
322
- |```sh
323
- -| $ for i in `seq 1 3`; do echo $i; done
324
- +| $ for i in `seq 1 4`; do echo $i; done
325
- | 1
326
- | 2
327
- | 3
328
- +| 4
329
- |```
330
- ```
331
-
332
- And the changes can then be accepted using:
333
-
334
- ```
335
- $ dune promote
336
- ```
337
-
338
- For further details about the mdx stanza you should read the
339
- [ according section] ( https://dune.readthedocs.io/en/latest/dune-files.html#mdx-since-2-4 )
340
- in the dune documentation.
341
-
342
266
#### Non-deterministic Tests
343
267
344
268
** Non-deterministic Outputs**
@@ -458,10 +382,3 @@ Those variables are then available in the subsequent blocks
458
382
bar
459
383
- : unit = ()
460
384
```
461
-
462
- ### Sections
463
-
464
- It is possible to test or execute only a subset of the file using
465
- sections using the ` --section ` option (short name is ` -s ` ). For
466
- instance ` ocaml-mdx pp -s foo ` will only consider the section matching the
467
- perl regular expression ` foo ` .
0 commit comments