realworldocaml / mdx

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

Rejecting legacy syntax prevents me from using some markdown features on code blocks #426

Open mbarbin opened 1 year ago

mbarbin commented 1 year ago

Hi!

I'm a new (and happy!) mdx user, but I've ran into an issue. Perhaps I'm simply confused ! Here is the issue I ran into, please let me know if I am misunderstanding something about the legacy syntax error.

Issue

I'd like to use mdx to keep some code block in sync with files living in the tree, but when I try adding mdx labels on top of my code blocks, I get an error regarding mixing legacy and new syntax.

An example using showLineNumbers from https://docusaurus.io/docs/markdown-features/code-blocks#line-numbering

<!-- $MDX file=my_file.ml -->
```ocaml showLineNumbers
(* Let `dune` promote your code block here *)
```

This renders fine in my doc, but this causes a mdx error when running dune runtest

[mdx] Fatal error: File "xxxxxxxx.md", lines 116-269: invalid code block: cannot mix both block labels syntax

which I think comes from that mdx error, from lib/block.ml:

 Error [ `Msg "cannot mix both block labels syntax" ]

I am guessing that you want to lead new users towards the new syntax, while preserving backward compatibility, so I think I understand the reason for this error in general. But I wonder if this is right to reject all code block properties, simply because some of them may be targeting other markdown tools. I don't expect you'd want mdx to handle all markdown properties out there. So if I'm understanding things correctly, I would like to propose to relax the rejection rule:

Proposal

Current behavior

Complain about mixing syntax and reject md files that have code block properties if they have a <!-- $MDX --> leading header.

Desired behavior

Complain about mixing syntax for mdx specific properties. Keep the code block properties mdx doesn't know about untouched, on the assumption that they might be targeting other tools.

Detailing my understanding of both syntaxes

Legacy vs New syntax

Legacy syntax

```ocaml prop=value
```

New syntax

<!-- $MDX prop=value -->
```ocaml
```