Skip to content

Commit c3bbf5b

Browse files
committed
readme: revamp introduction
- Fix dead links - Improve organization - Update the `using` clause's version - Add a compatability section. One TODO remains. - Make the example more interesting (by introducing an unintentional compilation error)
1 parent af8547a commit c3bbf5b

File tree

1 file changed

+87
-64
lines changed

1 file changed

+87
-64
lines changed

README.md

Lines changed: 87 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22

33
# MDX
44

5-
MDX allows to execute code blocks inside markdown and mli/mld documentation
6-
to help keeping them up to date.
5+
MDX is a tool that generates evaluation results for code interactions inside Markdown (`.md`)
6+
and `.ml{i,d}` documentation.
77

8-
Use the
9-
[dune stanza](https://dune.readthedocs.io/en/latest/dune-files.html#mdx-since-2-4)
10-
to enable it on your documentation.
11-
12-
`mdx` is released on opam and can be installed by running:
8+
MDX is released on opam and can be installed by running:
139

1410
```sh
1511
$ opam install mdx
@@ -18,110 +14,137 @@ $ opam install mdx
1814
If you want to contribute to the project, please see the
1915
[CONTRIBUTING.md](CONTRIBUTING.md).
2016

21-
## Basic Usage
17+
## Setup
2218

23-
You can use MDX with your Markdown or `.ml{i,d}` documentation, which ensures
24-
code in multi-line or verbatim code blocks is correct.
19+
MDX is integrated with Dune. To enable MDX for your Dune project,
20+
you must first add a [`dune-project` stanza](https://dune.readthedocs.io/en/latest/dune-files.html#mdx) to allow Dune to recognize MDX:
2521

26-
To enable MDX on specific files you must first enable it for your project by
27-
adding the following stanza to your `dune-project`:
2822
```
29-
(using mdx 0.2)
23+
(using mdx 0.4)
3024
```
3125

32-
Note that version `0.2` of the MDX stanza is only available in dune `3.0` or
33-
higher. You can use the first, `0.1` version with dune `2.4` or higher.
26+
See [compatibility](#compatibility) for more details about version compatibility.
27+
28+
Then add the following in relevant `dune` files:
3429

35-
Then add the following in the relevant `dune` file:
3630
```
37-
(mdx)
31+
(mdx (files :standard *.mli))
3832
```
39-
That enables MDX on all markdown files in the folder.
33+
34+
Under a folder with a `dune` file, `:standard` enables MDX on all Markdown files (`*.md`)
35+
and odoc's documentation pages (`*.mld`); `*.mli` enables MDX on the OCaml interface files.
4036
The MDX stanza can be further configured. Please visit the relevant section of
41-
[dune's manual](https://dune.readthedocs.io/en/latest/dune-files.html#mdx-since-2-4)
42-
for more information.
37+
[Dune's manual](https://dune.readthedocs.io/en/latest/dune-files.html#mdx) and
38+
the rest of this README for more information.
39+
40+
### Compatibility
41+
42+
- `(using mdx 0.1)` requires Dune 2.4 or higher, with no restriction on MDX version.
43+
- `(using mdx 0.2)` requires Dune 3.0 or higher and MDX 1.9.0 or higher.
44+
- `(using mdx 0.3)` requires TODO
45+
- `(using mdx 0.4)` requires Dune 3.8 or higher and MDX 2.3.0 or higher.
46+
47+
## Getting Started
4348

44-
MDX supports various type of code blocks but the most common are OCaml toplevel
45-
blocks. We illustrate one in our example below. In a Markdown file, you
46-
would write something similar to this:
49+
MDX supports various types of code blocks but the most common ones are OCaml interactive toplevel
50+
blocks. We illustrate one in the example below. In a Markdown file, we may have:
4751

4852
````markdown
49-
Let's look at how good OCaml is with integers and strings:
53+
Let's look at how good OCaml is with integers and floats:
5054
```ocaml
5155
# 1 + 2;;
5256
- : int = 2
53-
# "a" ^ "bc";;
54-
- : string = "ab"
57+
# 1.2 + 3.4;;
58+
- : float = 4.6
5559
```
5660
````
5761
or in an `mli` file:
5862
```ocaml
59-
(** Let's look at how good OCaml is with integers and strings:
63+
(** Let's look at how good OCaml is with integers and floats:
6064
{@ocaml[
6165
# 1 + 2;;
6266
- : int = 2
63-
# "a" ^ "bc";;
64-
- : string = "ab"
67+
# 1.2 + 3.4;;
68+
- : float = 4.6
6569
]}
6670
*)
6771
```
6872

69-
The content of the toplevel blocks looks just like an interactive toplevel
73+
The content of the interactive toplevel blocks looks just like an interactive toplevel
7074
session. Phrases, i.e., the toplevel "input", start with a `#` and end with `;;`.
7175
The toplevel evaluation, or "output" follows each phrase.
7276

73-
Now you probably have noticed that `1 + 2` is not equal to `2` nor is `"a" ^ "bc"`
74-
to `"ab"`. Somebody must have updated the phrases, but then forgot to update
75-
the evaluation.
77+
Now you probably have noticed that `1 + 2` is not equal to `2` nor is `1.2 + 3.4` type-checked.
78+
Somebody must have introduced a typo, or updated the phrases but then forgot to update the evaluation result.
7679

7780
That's exactly why MDX is here!
7881

79-
If you enable MDX for this file and then ran `dune runtest`, this would be the
80-
result:
82+
If we run `dune runtest`, this would be the result:
8183

82-
````
84+
````sh
8385
$ dune runtest
8486
File "README.md", line 1, characters 0-0:
85-
git (internal) (exit 1)
86-
(cd _build/default && /usr/bin/git --no-pager diff --no-index --color=always -u README.md .mdx/README.md.corrected)
87-
diff --git a/README.md b/.mdx/README.md.corrected
88-
index 181b86f..458ecec 100644
89-
--- a/README.md
90-
+++ b/.mdx/README.md.corrected
91-
@@ -1,13 +1,13 @@
92-
Let's look at how good OCaml is with integers and strings:
93-
```ocaml
94-
# 1 + 2;;
87+
diff --git a/_build/default/README.md b/_build/default/.mdx/README.md.corrected
88+
index e74437a..dfeeb64 100644
89+
--- a/_build/default/README.md
90+
+++ b/_build/default/.mdx/README.md.corrected
91+
@@ -1,7 +1,9 @@
92+
Let's look at how good OCaml is with integers and floats:
93+
```ocaml
94+
# 1 + 2;;
9595
-- : int = 2
9696
+- : int = 3
97-
# "a" ^ "bc";;
98-
-- : string = "ab"
99-
+- : string = "abc"
100-
```
97+
# 1.2 + 3.4;;
98+
-- : float = 4.6
99+
+Line 1, characters 1-4:
100+
+Error: This expression has type float but an expression was expected of type
101+
+ int
102+
```
101103
````
102104
103-
The test run just failed and dune is showing the diff between what we have
105+
The test run just failed and Dune is showing the diff between what we have
104106
locally and what should be, according to MDX.
105-
This uses dune's promotion workflow so at this point you can either investigate
106-
it further if you're surprised by this diff or if you're happy with it, simply
107-
accept it by running:
107+
This uses Dune's promotion workflow so that at this point we can investigate
108+
it further if we are surprised by this diff. In this case, we may want to fix
109+
the second phrase to `# 1.2 +. 3.4;;`. Then, we can re-run `dune runtest` again.
110+
111+
````sh
112+
$ dune runtest
113+
File "README.md", line 1, characters 0-0:
114+
diff --git a/_build/default/README.md b/_build/default/.mdx/README.md.corrected
115+
index 760debc..8e5878b 100644
116+
--- a/_build/default/README.md
117+
+++ b/_build/default/.mdx/README.md.corrected
118+
@@ -1,7 +1,7 @@
119+
Let's look at how good OCaml is with integers and floats:
120+
```ocaml
121+
# 1 + 2;;
122+
-- : int = 2
123+
+- : int = 3
124+
# 1.2 +. 3.4;;
125+
- : float = 4.6
126+
```
127+
````
128+
129+
Since we are now happy with the diff, we can accept it by running:
108130
109131
```
110132
dune promote
111133
```
112134
113-
Now the documentation is up-to-date and running `dune runtest` again should be
114-
successful!
115-
116-
Note that to use the `dune runtest/promote` workflow with `mli` or `mld` files,
117-
you will need to adjust the `mdx` stanza in the `dune` file, as by
118-
[default](https://dune.readthedocs.io/en/latest/dune-files.html#mdx-since-2-4),
119-
Dune only checks markdown files with `mdx`. E.g.,
135+
Now the documentation is up-to-date with the content:
120136
137+
````markdown
138+
Let's look at how good OCaml is with integers and floats:
139+
```ocaml
140+
# 1 + 2;;
141+
- : int = 3
142+
# 1.2 +. 3.4;;
143+
- : float = 4.6
121144
```
122-
(mdx
123-
(files :standard *.mli))
124-
```
145+
````
146+
147+
and running `dune runtest` again should be successful!
125148

126149
## Supported Extensions
127150

0 commit comments

Comments
 (0)