Skip to content

Commit

Permalink
add word-joiners between the question mark and the identifier of opti…
Browse files Browse the repository at this point in the history
…onal labels

cf. ocaml/odoc#19
  • Loading branch information
trefis committed May 27, 2017
1 parent 6222251 commit 18ac839
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/markup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ let make_spec ~get_package ~id ?doc code =
)

let arrow = span ~a:[ a_class ["keyword" ] ] [ entity "#8209"; entity "gt" ]

let label = function
| DocOck.Types.TypeExpr.Label s -> [ pcdata s ]
| Optional s -> [ pcdata "?"; entity "#8288"; pcdata s ]
4 changes: 4 additions & 0 deletions src/markup.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ val make_spec

val arrow : [> Html_types.span ] elt
(** "->" with a non breaking hyphen, styled as a keyword. *)

val label : DocOck.Types.TypeExpr.label -> [> `PCDATA ] elt list
(** For optional arguments adds a word joiner between the question mark and the
label. *)
9 changes: 2 additions & 7 deletions src/to_html_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ let functor_arg_pos { Types.FunctorArgument.id ; _ } =
let id = string_of_sexp @@ Identifier.sexp_of_t (fun _ -> Atom "") id in
invalid_arg (Printf.sprintf "functor_arg_pos: %s" id)


let string_of_label = function
| Types.TypeExpr.Label s -> s
| Optional s -> "?" ^ s

let rec unit ~get_package (t : _ Types.Unit.t) : Html_tree.t =
let package =
match t.id with
Expand Down Expand Up @@ -730,7 +725,7 @@ and type_expr
if not needs_parentheses then res else pcdata "(" :: res @ [pcdata ")"]
| Arrow (Some lbl, src, dst) ->
let res =
pcdata (string_of_label lbl ^ ":") ::
Markup.label lbl @ pcdata ":" ::
type_expr ~needs_parentheses:true ~get_package src @
pcdata " " :: Markup.arrow :: pcdata " " :: type_expr ~get_package dst
in
Expand Down Expand Up @@ -880,7 +875,7 @@ and class_decl
type_expr ~needs_parentheses:true ~get_package src @
pcdata " " :: Markup.arrow :: pcdata " " :: class_decl ~get_package dst
| Arrow (Some lbl, src, dst) ->
pcdata (string_of_label lbl ^ ":") ::
Markup.label lbl @ pcdata ":" ::
type_expr ~needs_parentheses:true ~get_package src @
pcdata " " :: Markup.arrow :: pcdata " " :: class_decl ~get_package dst

Expand Down

0 comments on commit 18ac839

Please sign in to comment.