realworldocaml / mdx

Execute code blocks inside your documentation
ISC License
265 stars 45 forks source link

Fix multilines for OCaml block in .mli file #395

Closed panglesd closed 2 years ago

panglesd commented 2 years ago

This small PR fixes the fact that, in OCaml blocks, in .mli files, the indentation was erased to a "only 2 space relative to the opening bracket" indentation.

For instance,

(**
{[
  match None with
  | None -> ()
  | Some a -> match a with
    | None -> ()
    | Some _ -> ()
]}
*)

was turned into

(**
{[
  match None with
  | None -> ()
  | Some a -> match a with
  | None -> ()
  | Some _ -> ()
]}
*)

which is not ideal.

The first commit adds a test, showing the wrong behaviour,. The second commit is the patch and updates the test. The new behaviour is the first line is indented two spaces after the opening bracket, and for other lines the indentation relative to the first one is kept, as long as they are at least as indented as the first one. In the previous example, the exact indententation would be kept.

In the test, I also added that multilines in .mli files for toplevel block does not work!

Leonidas-from-XIV commented 2 years ago

Oh, as I am seeing the CI runs, can you add a changelog entry?

Leonidas-from-XIV commented 2 years ago

Thanks @panglesd for your help, I'll try to bundle a few of these fixes that have PRs and make a release soon.