Skip to content

Commit abf4a61

Browse files
committed
Make sure the delimiter is not used in the error-block content
1 parent c35dddb commit abf4a61

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/block.ml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,34 @@ let rec error_padding = function
161161
let xs = error_padding xs in
162162
x :: xs
163163

164+
let compute_delimiter ~base_delim outputs =
165+
let s =
166+
Format.asprintf "%a" (Format.pp_print_list (Output.pp ~pad:0)) outputs
167+
in
168+
let is_inadequate delim =
169+
Astring.String.is_infix ~affix:("]" ^ delim ^ "}") s
170+
in
171+
let rec loop n =
172+
let delim =
173+
match n with 0 -> base_delim | n -> Format.sprintf "%s_%d" base_delim n
174+
in
175+
if is_inadequate delim then loop (n + 1) else delim
176+
in
177+
loop 0
178+
164179
let pp_error ?syntax ?delim ppf outputs =
165180
match syntax with
166181
| Some Syntax.Markdown ->
167182
Fmt.pf ppf "```\n```mdx-error\n%a\n"
168183
Fmt.(list ~sep:(any "\n") Output.pp)
169184
outputs
170185
| Some Syntax.Mli | Some Syntax.Mld ->
171-
Fmt.pf ppf "]%a[\n{err@mdx-error[\n%a\n]err}"
186+
let err_delim = compute_delimiter ~base_delim:"err" outputs in
187+
Fmt.pf ppf "]%a[\n{%s@mdx-error[\n%a\n]%s}"
172188
Fmt.(option string)
173-
delim
189+
delim err_delim
174190
Fmt.(list ~sep:(any "\n") Output.pp)
175-
outputs
191+
outputs err_delim
176192
| _ -> ()
177193

178194
let has_output t =

0 commit comments

Comments
 (0)