summaryrefslogtreecommitdiff
path: root/ocamldoc/odoc_man.ml
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2019-11-12 16:49:03 +0100
committerGabriel Scherer <gabriel.scherer@gmail.com>2019-11-14 11:31:05 +0100
commit757a64464f66ddc5600ea7ac2fb7bbc40842c068 (patch)
treeaf70e094335942d4fdcf74b7f825192a93713516 /ocamldoc/odoc_man.ml
parentfe78f2403ce4a691933c5dd4da6bee04d7ec2395 (diff)
downloadocaml-757a64464f66ddc5600ea7ac2fb7bbc40842c068.tar.gz
ocamldoc: better support of multiline code blocks in the manpage backend
Before, `man Map` would show: ``` For instance: module IntPairs = struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with 0 -> Stdlib.compare y0 y1 | c -> c end module PairsMap = Map.Make(IntPairs) let m = PairsMap.(empty |> add (0,1) hello |> add (1,0) world ) ``` Now it shows: ``` For instance: module IntPairs = struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with 0 -> Stdlib.compare y0 y1 | c -> c end module PairsMap = Map.Make(IntPairs) let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world") ``` (in both cases the code is in bold)
Diffstat (limited to 'ocamldoc/odoc_man.ml')
-rw-r--r--ocamldoc/odoc_man.ml14
1 files changed, 7 insertions, 7 deletions
diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml
index 3f4ddf4c02..f4ebaadea1 100644
--- a/ocamldoc/odoc_man.ml
+++ b/ocamldoc/odoc_man.ml
@@ -287,12 +287,8 @@ class man =
method man_of_text_element b txt =
match txt with
| Odoc_info.Raw s -> bs b (self#escape s)
- | Odoc_info.Code s ->
- bs b "\n.B ";
- bs b ((Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n")
- | Odoc_info.CodePre s ->
- bs b "\n.B ";
- bs b ((Str.global_replace (Str.regexp "\n") "\n.B " (self#escape s))^"\n")
+ | Odoc_info.Code s -> self#man_of_code b s
+ | Odoc_info.CodePre s -> self#man_of_code b s
| Odoc_info.Verbatim s ->
bs b (self#escape s)
| Odoc_info.Bold t
@@ -346,7 +342,11 @@ class man =
if String.lowercase_ascii target = "man" then bs b code else ()
(** Print groff string to display code. *)
- method man_of_code b s = self#man_of_text b [ Code s ]
+ method man_of_code b code =
+ let code = self#escape code in
+ bs b "\n.ft B\n";
+ bs b (Str.global_replace (Str.regexp "\n") "\n.br\n\\&" code);
+ bs b "\n.ft R\n";
(** Take a string and return the string where fully qualified idents
have been replaced by idents relative to the given module name.*)