Open sorawee opened 11 months ago
@Julow Here's the actual result of #1+1;;
after this PR:
{@ocaml[
#1+1;;
][
{err@mdx-error[
Line 1, characters 4-5:
Error: Syntax error
]err}]}
This is because #1+1;;
makes the block considered the ocaml
block type due to the absence of space after #
.
Prior this PR, the following code fails:
because MDX incorrectly infers that the code block is a toplevel interaction (from the fact that the block starts with
#
), resulting in an error:It is possible to workaround this issue as suggested in #421 by adding a comment as a first line.
but ideally the workaround should not be needed.
One may wonder why the inference is needed, since the above code block is already specified to be in the
ocaml
mode. The answer appears to be that we are expected to use the inference heuristics for a light sanity check, as the existing tests ("invalid ocaml" and "invalid toplevel" intest_block.ml
) require:As a result, this PR keeps the light sanity check intact, but adjusts the inference heuristics to be more conservative. A block is now considered a toplevel interaction when it starts with
#
followed by a space. This fixes the issue, making it possible to use directives. As a bonus, directives will now also work even when the mode is not specified at all. But one disadvantage is that this kind of code will no longer be considered invalid.