44
55` mdx ` allows to execute code blocks inside markdown files.
66There are (currently) two sub-commands, corresponding
7- to two modes of operations: pre-processing (` mdx pp ` )
8- and tests (` mdx test ` ).
7+ to two modes of operations: pre-processing (` ocaml- mdx pp` )
8+ and tests (` ocaml- mdx test` ).
99
1010The pre-processor mode allows to mix documentation and code,
1111and to practice "literate programming" using markdown and OCaml.
1212
1313The test mode allows to ensure that shell scripts and OCaml fragments
1414in the documentation always stays up-to-date.
1515
16- ` mdx ` is released as a single binary (called ` mdx ` ) and
16+ ` mdx ` is released as a single binary (called ` ocaml- mdx` ) and
1717can be installed using opam:
1818
1919``` sh
@@ -24,7 +24,7 @@ $ opam install mdx
2424
2525#### Shell Scripts
2626
27- ` mdx ` interprets shell scripts inside ` sh ` code blocks as cram-like tests. The
27+ ` ocaml- mdx` interprets shell scripts inside ` sh ` code blocks as cram-like tests. The
2828syntax is the following:
2929
3030- Lines beginning with a dollar sign and a space are
@@ -63,7 +63,7 @@ with a padding of 3:
6363 10
6464 ```
6565
66- ` mdx ` will also consider exit codes when the syntax ` [<exit code>] ` is used:
66+ ` ocaml- mdx` will also consider exit codes when the syntax ` [<exit code>] ` is used:
6767
6868 ```sh
6969 $ exit 1
@@ -75,7 +75,7 @@ of success).
7575
7676#### OCaml Code
7777
78- ` mdx ` interprets OCaml fragments. It understands _ normal_ code fragments and
78+ ` ocaml- mdx` interprets OCaml fragments. It understands _ normal_ code fragments and
7979_ toplevel_ code fragments (starting with a ` # ` sign and optionally ending with
8080` ;; ` ). Arbitrary whitespace padding is supported, at long as it stays
8181consistent within a code block.
@@ -97,7 +97,7 @@ Here is an examples of toplevel OCaml code:
9797
9898### Pre-processing
9999
100- ` mdx pp ` allows to transform a markdown file into a valid
100+ ` ocaml- mdx pp` allows to transform a markdown file into a valid
101101OCaml file, which can be passed to OCaml using the ` -pp `
102102option.
103103
@@ -111,7 +111,7 @@ For instance, given the following `file.md` document:
111111Can be compiled and executed using:
112112
113113``` sh
114- $ ocamlc -pp ' mdx pp' -impl file.md -o file.exe
114+ $ ocamlc -pp ' ocaml- mdx pp' -impl file.md -o file.exe
115115$ ./file.exe
11611642
117117```
@@ -122,7 +122,7 @@ This can be automated using `dune`:
122122(rule
123123 ((targets (file.ml))
124124 (deps (file.md))
125- (action (with-stdout-to ${@} (run mdx pp ${<})))))
125+ (action (with-stdout-to ${@} (run ocaml- mdx pp ${<})))))
126126
127127(executable ((name file)))
128128```
@@ -131,7 +131,7 @@ This can be automated using `dune`:
131131
132132#### Cram Tests
133133
134- Cram tests can be executed and checked with ` mdx test <file.md> ` .
134+ Cram tests can be executed and checked with ` ocaml- mdx test <file.md>` .
135135
136136 ```sh
137137 $ for i in `seq 1 10`; do echo $i; done
@@ -145,7 +145,7 @@ If the output is not consistent with what is expected,
145145
146146#### OCaml
147147
148- To execute OCaml code and toplevel fragments, uses ` mdx test <file.md> ` .
148+ To execute OCaml code and toplevel fragments, uses ` ocaml- mdx test <file.md>` .
149149
150150 ```ocaml
151151 # print_endline "42"
@@ -162,11 +162,11 @@ dune's `diff?` stanza:
162162
163163```
164164(alias
165- ( (name runtest)
166- (deps (file.md))
165+ (name runtest)
166+ (deps (:test file.md))
167167 (action (progn
168- (run mdx test ${< })
169- (diff? ${<} ${< }.corrected) ))))
168+ (run ocaml- mdx test %{test })
169+ (diff? %{test} %{test }.corrected))))
170170```
171171
172172This allows to test the consistency of a markdown file using the normal dev
@@ -204,7 +204,7 @@ $ dune promote
204204
205205** Non-deterministic Outputs**
206206
207- ` mdx test ` supports non-deterministic outputs:
207+ ` ocaml- mdx test` supports non-deterministic outputs:
208208
209209 ```sh non-deterministic=output
210210 $ <command>
@@ -213,19 +213,19 @@ $ dune promote
213213
214214In that case, ` ppx test <file> ` will run the command but will not
215215generate ` <file>.corrected ` if the new output differs from the one
216- described in the file. Use ` mdx test --non-deterministic <file> ` to come
216+ described in the file. Use ` ocaml- mdx test --non-deterministic <file>` to come
217217back to the default behaviour.
218218
219219** Non-deterministic Commands**
220220
221- ` mdx test ` supports non-deterministic commands:
221+ ` ocaml- mdx test` supports non-deterministic commands:
222222
223223 ```ocaml non-deterministic=command
224224 # Random.int 10;;
225225 - : int = 5
226226 ```
227227
228- In that case, ` mdx test <file> ` will * not* run the command. Use `mdx test
228+ In that case, ` ocaml- mdx test <file>` will * not* run the command. Use `ocaml- mdx test
229229--non-deterministic <file >` to come back to the default behaviour.
230230
231231#### Named execution environments (since mdx 1.1.0)
@@ -294,39 +294,39 @@ The version number can be of the following forms:
294294
295295Environment variables can be declared at the beginning of a block:
296296
297- ``` ocaml set-FOO=bar,set-BAR=foo
298- # print_endline (Sys.getenv "FOO")
299- bar
300- - : unit = ()
301- # print_endline (Sys.getenv "BAR")
302- foo
303- - : unit = ()
304- ```
297+ ```ocaml set-FOO=bar,set-BAR=foo
298+ # print_endline (Sys.getenv "FOO")
299+ bar
300+ - : unit = ()
301+ # print_endline (Sys.getenv "BAR")
302+ foo
303+ - : unit = ()
304+ ```
305305
306306Those variables are then available in the subsequent blocks
307307
308- ``` ocaml
309- # print_endline (Sys.getenv "FOO")
310- bar
311- - : unit = ()
312- ```
308+ ```ocaml
309+ # print_endline (Sys.getenv "FOO")
310+ bar
311+ - : unit = ()
312+ ```
313313
314314### Sections
315315
316316It is possible to test or execute only a subset of the file using
317317sections using the ` --section ` option (short name is ` -s ` ). For
318- instance ` mdx pp -s foo ` will only consider the section matching the
318+ instance ` ocaml- mdx pp -s foo` will only consider the section matching the
319319perl regular expression ` foo ` .
320320
321321### Dune rules (since mdx 1.1.0)
322322
323- ` mdx ` can generate ` dune ` rules to synchronize .md files with .ml files.
323+ ` ocaml- mdx` can generate ` dune ` rules to synchronize .md files with .ml files.
324324
325325Consider the test/dune_rules.md file that contains blocks referring to files
326326dune_rules_1.ml and dune_rules_2.ml, running:
327327
328328```
329- $ mdx rule test/dune_rules.md
329+ $ ocaml- mdx rule test/dune_rules.md
330330```
331331
332332generates the following ` dune ` rules on the standard output:
@@ -338,7 +338,7 @@ generates the following `dune` rules on the standard output:
338338 (:y0 dune_rules_2.ml)
339339 (source_tree foo))
340340 (action (progn
341- (run mdx test --direction=infer-timestamp %{x})
341+ (run ocaml- mdx test --direction=infer-timestamp %{x})
342342 (diff? %{x} %{x}.corrected)
343343 (diff? %{y1} %{y1}.corrected)
344344 (diff? %{y0} %{y0}.corrected))))
0 commit comments