Skip to content

Commit

Permalink
Make sure the delimiter is not used in the error-block content
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Oct 25, 2023
1 parent c35dddb commit abf4a61
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,34 @@ let rec error_padding = function
let xs = error_padding xs in
x :: xs

let compute_delimiter ~base_delim outputs =
let s =
Format.asprintf "%a" (Format.pp_print_list (Output.pp ~pad:0)) outputs
in
let is_inadequate delim =
Astring.String.is_infix ~affix:("]" ^ delim ^ "}") s
in
let rec loop n =
let delim =
match n with 0 -> base_delim | n -> Format.sprintf "%s_%d" base_delim n
in
if is_inadequate delim then loop (n + 1) else delim
in
loop 0

let pp_error ?syntax ?delim ppf outputs =
match syntax with
| Some Syntax.Markdown ->
Fmt.pf ppf "```\n```mdx-error\n%a\n"
Fmt.(list ~sep:(any "\n") Output.pp)
outputs
| Some Syntax.Mli | Some Syntax.Mld ->
Fmt.pf ppf "]%a[\n{err@mdx-error[\n%a\n]err}"
let err_delim = compute_delimiter ~base_delim:"err" outputs in
Fmt.pf ppf "]%a[\n{%s@mdx-error[\n%a\n]%s}"
Fmt.(option string)
delim
delim err_delim
Fmt.(list ~sep:(any "\n") Output.pp)
outputs
outputs err_delim
| _ -> ()

let has_output t =
Expand Down

0 comments on commit abf4a61

Please sign in to comment.