Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add a manual using odoc and .mld files #355

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#### Added

- Report all parsing errors in Markdown files (#389, @NathanReb)
- Add alternative syntax for explicitly setting the block-type.
The new label `block-type=...` can be set to `ocaml`, `toplevel`, `cram` or
`include`. (#385, @NathanReb)

#### Changed

Expand Down
2 changes: 2 additions & 0 deletions doc/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(documentation
(package mdx))
2 changes: 2 additions & 0 deletions doc/dune_stanza.mld
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{0 Dune Stanza}

111 changes: 111 additions & 0 deletions doc/index.mld
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{0 MDX Manual}

Welcome to the MDX Manual!

MDX is a tool to help developpers and authors keep their documentation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MDX is a tool to help developpers and authors keep their documentation
MDX is a tool to help developers and authors keep their documentation

up-to-date.
It ensures that the code examples you write compile and behave the way you
expect them to by actually running them.
Comment on lines +7 to +8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It ensures that the code examples you write compile and behave the way you
expect them to by actually running them.
It ensures your code examples compile and behave the way you
expect by actually running them.


It is for example used to verify all of

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is for example used to verify all of
For example, you can use MDX to verify all

{{:https://dev.realworldocaml.org/}Realworlocaml}'s examples!

MDX is released on opam. You can install it in your switch by running:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MDX is released on opam. You can install it in your switch by running:
MDX is released on Opam, so you can install it in your switch by running:

{@sh[
opam install mdx
]}

{1 Table of Content}
- {{!page-markdown_syntax}Markdown MDX Syntax}
- {{!page-mli_syntax}.mli MDX Syntax}
- {{!page-types_of_blocks}Types of Blocks}
- {{!page-labels}Labels}
- {{!page-dune_stanza}Dune stanza}
- {{!page-preludes}Preludes}
- {{!page-using_libs}Using Libraries in your code examples}

{1 Basic Usage}

You can use MDX with your Markdown or [.mli] documentation, where it will ensure

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can use MDX with your Markdown or [.mli] documentation, where it will ensure
You can use MDX with your Markdown or [.mli] documentation, which ensures

the correctness of code respectively written in multi-line code blocks and

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
the correctness of code respectively written in multi-line code blocks and
correct code written in multiline code blocks and

verbatim code blocks.

To enable MDX, you need to add [(mdx)] stanzas to the right dune files. Before
that you will need to enable MDX for your project by adding the following to
your [dune-project]:
Comment on lines +33 to +35

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To enable MDX, you need to add [(mdx)] stanzas to the right dune files. Before
that you will need to enable MDX for your project by adding the following to
your [dune-project]:
To enable MDX, you need to add [(mdx)] stanzas to the right [dune] files. Before
that you must enable MDX for your project by adding the following to
your [dune-project]:

(If wrapping text in [ ] creates monospace in .mld)


{@dune[
(using mdx 0.2)
]}

You can then add the following in the relevant dune file:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You can then add the following in the relevant dune file:
Then add the following in the relevant [dune] file:

{@dune[
(mdx)
]}
That will enable MDX on all markdown files in the folder.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
That will enable MDX on all markdown files in the folder.
That enables MDX on all markdown files in the folder.

The MDX stanza can be further configured. If you want to know more about it,
visit the {{!page-mdx_dune_stanza}corresponding section of this manual} or the
one in
{{:https://dune.readthedocs.io/en/latest/dune-files.html#mdx-since-2-4}dune's manual}.

MDX supports various type of code blocks but the most common are OCaml toplevel
blocks so we'll look at one of those for our example. In a markdown file, you
would write something along those lines:
Comment on lines +51 to +53

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
MDX supports various type of code blocks but the most common are OCaml toplevel
blocks so we'll look at one of those for our example. In a markdown file, you
would write something along those lines:
MDX supports various type of code blocks, but the most common are OCaml toplevel
blocks. We illustrate one in our example below. In a Markdown file, you
would write something similar to this:


{@markdown[
Let's look at how good OCaml is with integers and strings:
```ocaml
# 1 + 2;;
- : int = 2
# "a" ^ "bc";;
- : string = "ab"
```
]}

The content of the toplevel blocks looks just like an interactive toplevel
session. Phrases, i.e. the toplevel "input", start with a [#] and end with [;;].
Each of them is followed by the toplevel evaluation, or "output" which you
probably are already familiar with.
Comment on lines +66 to +68

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
session. Phrases, i.e. the toplevel "input", start with a [#] and end with [;;].
Each of them is followed by the toplevel evaluation, or "output" which you
probably are already familiar with.
session. Phrases, i.e., the toplevel "input", start with a [#] and end with [;;].
The toplevel evaluation follows each of them, or you can alternatively use "output", which you
might already be familiar with.


Now you probably have noticed that [1 + 2] is not equal to [3] nor ["a" ^ "bc"]
to ["ab"]. Somebody must have updated the phrases but they then forgot to update
the evaluation.
Comment on lines +70 to +72

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Now you probably have noticed that [1 + 2] is not equal to [3] nor ["a" ^ "bc"]
to ["ab"]. Somebody must have updated the phrases but they then forgot to update
the evaluation.
Now you probably have noticed that [1 + 2] is not equal to [3] nor ["a" ^ "bc"]
to ["ab"]. Somebody must have updated the phrases, but they then forgot to update
the evaluation.


That's exactly what MDX is here for!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
That's exactly what MDX is here for!
That's exactly why MDX is here!


If MDX were enabled for this file and they ran [dune runtest], here's what they
would have gotten:
Comment on lines +76 to +77

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If MDX were enabled for this file and they ran [dune runtest], here's what they
would have gotten:
If you enabled MDX for this file and then ran [dune runtest], this would be the result:


{@sh[
$ dune runtest
File "README.md", line 1, characters 0-0:
git (internal) (exit 1)
(cd _build/default && /usr/bin/git --no-pager diff --no-index --color=always -u README.md .mdx/README.md.corrected)
diff --git a/README.md b/.mdx/README.md.corrected
index 181b86f..458ecec 100644
--- a/README.md
+++ b/.mdx/README.md.corrected
@@ -1,13 +1,13 @@
Let's look at how good OCaml is with integers and strings:
```ocaml
# 1 + 2;;
-- : int = 2
+- : int = 3
# "a" ^ "bc";;
-- : string = "ab"
+- : string = "abc"
```
]}

The test run just failed and dune is showing the diff between what we have
locally and what should be, according to MDX.
This uses dune's promotion workflow so at this point you can either investigate
it further if you're surprised by this diff or if you're happy with it, simply
accept it by running:
Comment on lines +100 to +104

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The test run just failed and dune is showing the diff between what we have
locally and what should be, according to MDX.
This uses dune's promotion workflow so at this point you can either investigate
it further if you're surprised by this diff or if you're happy with it, simply
accept it by running:
The test run just failed, and Dune shows the diff between what we have
locally and what we should have, according to MDX.
This uses Dune's promotion workflow. At this point, you can either investigate further
(if you're surprised by this diff), or if you're happy with it, simply
accept it by running:


{@sh[
dune promote
]}

Now the documentation is up-to-date and running [dune runtest] again should be
successful!
Loading