Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

### Changes

- Improve escaping of `@` in doc-comments (#2377, @Julow)
- Disable reporting of deprecated alerts while formatting code blocks (#2373, @Julow)
- Improve indentation of `as`-patterns (#2359, @Julow)
- Restore short form for first-class modules: `((module M) : (module S))` is formatted as `(module M : S)`) (#2280, #2300, @gpetiot, @Julow)
Expand Down
22 changes: 8 additions & 14 deletions lib/Fmt_odoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ let escape_brackets s =
ensure_escape ~escapeworthy s

let escape_all s =
let escapeworthy = function
| '@' | '{' | '}' | '[' | ']' -> true
| _ -> false
in
let escapeworthy = function '{' | '}' | '[' | ']' -> true | _ -> false in
ensure_escape ~escapeworthy s

let split_on_whitespaces =
Expand Down Expand Up @@ -177,22 +174,19 @@ let rec fmt_inline_elements c elements =
in
let rec aux = function
| [] -> noop
| `Space sp :: `Word w :: t ->
(* Escape lines starting with '+' or '-' *)
let escape =
if String.length w > 0 && Char.(w.[0] = '+' || w.[0] = '-') then
"\\"
else ""
in
| `Space sp :: `Word (("-" | "+") as w) :: t ->
(* Escape lines starting with '+' or '-'. *)
fmt_or_k c.conf.fmt_opts.wrap_docstrings.v
(cbreak ~fits:("", 1, "") ~breaks:("", 0, escape))
(cbreak ~fits:("", 1, "") ~breaks:("", 0, "\\"))
(non_wrap_space sp)
$ str_normalized c w $ aux t
$ str w $ aux t
| `Space sp :: t ->
fmt_or_k c.conf.fmt_opts.wrap_docstrings.v (fmt "@ ")
(non_wrap_space sp)
$ aux t
| `Word w :: t -> str_normalized c w $ aux t
| `Word w :: t ->
fmt_if (String.is_prefix ~prefix:"@" w) "\\"
$ str_normalized c w $ aux t
| `Code_span s :: t -> fmt_code_span s $ aux t
| `Math_span s :: t -> fmt_math_span s $ aux t
| `Raw_markup (lang, s) :: t ->
Expand Down
4 changes: 4 additions & 0 deletions test/passing/tests/doc_comments-no-parse-docstrings.mli.ref
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,7 @@ type x =

(** ISO-Latin1 characters in identifiers
{[ω]}*)

(** at@ *)

(** \@at *)
4 changes: 4 additions & 0 deletions test/passing/tests/doc_comments-no-wrap.mli.ref
Original file line number Diff line number Diff line change
Expand Up @@ -636,3 +636,7 @@ type x =
{[
ω
]}*)

(** at@ *)

(** \@at *)
3 changes: 3 additions & 0 deletions test/passing/tests/doc_comments.mli
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,6 @@ type x =

(** ISO-Latin1 characters in identifiers
{[ω]}*)

(** at@ *)
(** \@at *)
4 changes: 4 additions & 0 deletions test/passing/tests/doc_comments.mli.ref
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,7 @@ type x =
{[
ω
]}*)

(** at@ *)

(** \@at *)