-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: main
Are you sure you want to change the base?
Changes from all commits
8e02014
53bfb95
64cd796
426bd17
dad5f33
dfc13b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(documentation | ||
(package mdx)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{0 Dune Stanza} | ||
|
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 | ||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
It is for example used to verify all of | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
{{:https://dev.realworldocaml.org/}Realworlocaml}'s examples! | ||||||||||||||||||||||
|
||||||||||||||||||||||
MDX is released on opam. You can install it in your switch by running: | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
{@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 | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(If wrapping text in [ ] creates monospace in .mld) |
||||||||||||||||||||||
|
||||||||||||||||||||||
{@dune[ | ||||||||||||||||||||||
(using mdx 0.2) | ||||||||||||||||||||||
]} | ||||||||||||||||||||||
|
||||||||||||||||||||||
You can then add the following in the relevant dune file: | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
{@dune[ | ||||||||||||||||||||||
(mdx) | ||||||||||||||||||||||
]} | ||||||||||||||||||||||
That will enable MDX on all markdown files in the folder. | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
{@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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||||||||||||||||
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
That's exactly what MDX is here for! | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||||||||||||||||||||||
Comment on lines
+76
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
{@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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
{@sh[ | ||||||||||||||||||||||
dune promote | ||||||||||||||||||||||
]} | ||||||||||||||||||||||
|
||||||||||||||||||||||
Now the documentation is up-to-date and running [dune runtest] again should be | ||||||||||||||||||||||
successful! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.