Mdx, ppx, labels in mld

Hello,

I have questions about mdx.

  1. Is there a way to have mdx preprocess the code in blocks given a given ppx? There is this post but it doesn’t quite answer the question
  2. The only documentation I can find about mdx is its own readme, but it does not explain how to add labels to code blocks in mld files, it only explains how to do so in md files. Is it possible to so?

Thanks to anyone who has answers !

1 Like

Hi, the technique I had mentioned works in markdown files, but I’m not sure if it’d work in mld files, I have vague memory of them having slightly different behavior when I tried.

Here’s an example where the code mentioned in the README has been compiled, so no mistakes could be present in the documentation, which is what I was after (I’m not sure it answers your question though)

Hmm, I do have my ppx imported in the libraries field of the mdx stanza. But I still get the “uninterpreted extension error”, in both md and mld files :confused:

Ok yes, I missed the fact that you needed both the ppx in your libraries field and to call #require in your prelude.

And for the second one, I looked at the doc again with a fresh eye and found the syntax there :upside_down_face:

It sounds like you managed to have ppx extensions work in md as well? If you have a github account, I’d like to kindly request you to add a link towards your solution here Add support for preprocessors in the ocaml fragments of mdx files · Issue #441 · realworldocaml/mdx · GitHub please (sounds like you have resolved that issue, which sounds lovely!).

Other things I have been stuck with mdx at earlier points, which I’d be interested with in case you end up looking into these parts (haven’t tried in a while):

Expect-tests ?

let%expect_test "hello" =
  print_endline "Hello";
  [%expect {||}];
  ()
;;
Line 1, characters 5-16:
Error: Uninterpreted extension 'expect_test'.

If you skip them, obviously the workflow is lost.

let%expect_test "hello" =
  print_endline "Hello";
  [%expect {| STALE |}];
  ()
;;

Sounds like this may get solved by the same fix you’ve found for ppx. hopefully this will work now!

merlin / lsp support

Didn’t work last I checked. Try hovering on the code below in vscode, nothing is shown.

let s = "Hello"

Jump to compile error in vscode also wasn’t as precise as in normal ml/mli files.

ocamlformat

Not supported last I checked.

let      (    )    =
 ignore [ `please ;
`format
;               `my
     ; `code
 ]