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
19 changes: 11 additions & 8 deletions src/html/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -368,24 +368,27 @@ module Page = struct
| `Closed | `Open | `Default -> None
| `Inline -> Some 0 )

let rec include_ ?theme_uri { Subpage.content; _ } =
[ page ?theme_uri content ]
let rec include_ ?theme_uri indent { Subpage.content; _ } =
[ page ?theme_uri indent content ]

and subpages ?theme_uri i =
Utils.list_concat_map ~f:(include_ ?theme_uri) @@ Doctree.Subpages.compute i
and subpages ?theme_uri indent i =
Utils.list_concat_map ~f:(include_ ?theme_uri indent)
@@ Doctree.Subpages.compute i

and page ?theme_uri ({ Page.title; header; items = i; url } as p) =
and page ?theme_uri indent ({ Page.title; header; items = i; url } as p) =
let resolve = Link.Current url in
let i = Doctree.Shift.compute ~on_sub i in
let toc = Toc.from_items ~resolve ~path:url i in
let subpages = subpages ?theme_uri p in
let subpages = subpages ?theme_uri indent p in
let header = items ~resolve header in
let content = (items ~resolve i :> any Html.elt list) in
let page = Tree.make ?theme_uri ~header ~toc ~url title content subpages in
let page =
Tree.make ?theme_uri ~indent ~header ~toc ~url title content subpages
in
page
end

let render ?theme_uri page = Page.page ?theme_uri page
let render ?theme_uri ~indent page = Page.page ?theme_uri indent page

let doc ~xref_base_uri b =
let resolve = Link.Base xref_base_uri in
Expand Down
2 changes: 1 addition & 1 deletion src/html/generator.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Odoc_document

val render : ?theme_uri:Tree.uri -> Types.Page.t -> Renderer.page
val render : ?theme_uri:Tree.uri -> indent:bool -> Types.Page.t -> Renderer.page

val doc :
xref_base_uri:string ->
Expand Down
4 changes: 2 additions & 2 deletions src/html/tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ let page_creator ?(theme_uri = Relative "./") ~url name header toc content =
in
Html.html head (Html.body body)

let make ?theme_uri ~url ~header ~toc title content children =
let make ?theme_uri ~indent ~url ~header ~toc title content children =
let filename = Link.Path.as_filename url in
let html = page_creator ?theme_uri ~url title header toc content in
let content ppf = (Html.pp ()) ppf html in
let content ppf = (Html.pp ~indent ()) ppf html in
{ Odoc_document.Renderer.filename; content; children }

let open_details = ref true
1 change: 1 addition & 0 deletions src/html/tree.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type uri =

val make :
?theme_uri:uri ->
indent:bool ->
url:Url.Path.t ->
header:Html_types.flow5_without_header_footer Html.elt list ->
toc:Html_types.flow5 Html.elt list ->
Expand Down
10 changes: 7 additions & 3 deletions src/odoc/bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ module Odoc_html = Make_renderer (struct
in
Arg.(value & flag (info ~doc [ "closed-details" ]))

let indent =
let doc = "Format the output HTML files with indentation" in
Arg.(value & flag (info ~doc [ "indent" ]))
Comment on lines +380 to +382
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about enabling it by default without exposing the option ? Whitespaces compress well and indented output is always nicer to look at.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could do - I've got no strong views on this. I've added it because my previous script was just running things through html tidy, and the larger my test set got the slower the tidying got!


(* Very basic validation and normalization for URI paths. *)
let convert_uri : Odoc_html.Tree.uri Arg.converter =
let parser str =
Expand Down Expand Up @@ -409,10 +413,10 @@ module Odoc_html = Make_renderer (struct
value & opt convert_uri default & info ~docv:"URI" ~doc [ "theme-uri" ])

let extra_args =
let f semantic_uris closed_details theme_uri =
{ Html_page.semantic_uris; closed_details; theme_uri }
let f semantic_uris closed_details indent theme_uri =
{ Html_page.semantic_uris; closed_details; theme_uri; indent }
in
Term.(const f $ semantic_uris $ closed_details $ theme_uri)
Term.(const f $ semantic_uris $ closed_details $ indent $ theme_uri)
end)

module Html_fragment : sig
Expand Down
3 changes: 2 additions & 1 deletion src/odoc/html_page.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ open Odoc_document
type args = {
semantic_uris : bool;
closed_details : bool;
indent : bool;
theme_uri : Odoc_html.Tree.uri;
}

let render args page =
Odoc_html.Link.semantic_uris := args.semantic_uris;
Odoc_html.Tree.open_details := not args.closed_details;
Odoc_html.Generator.render ~theme_uri:args.theme_uri page
Odoc_html.Generator.render ~theme_uri:args.theme_uri ~indent:args.indent page

let files_of_url url = [ Odoc_html.Link.Path.as_filename url ]

Expand Down
1 change: 1 addition & 0 deletions src/odoc/html_page.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ open Odoc_document
type args = {
semantic_uris : bool;
closed_details : bool;
indent : bool;
theme_uri : Odoc_html.Tree.uri;
}

Expand Down
2 changes: 1 addition & 1 deletion src/xref2/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ and content env id =
| Module m ->
let sg = Type_of.signature env m in
Module (signature env (id :> Id.Signature.t) sg)
| Pack _ -> failwith "Unhandled content"
| Pack p -> Pack p
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How hard would it be to actually compile packs ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not even looked into it to be honest - not many packages use packing right now, but the one I have installed was causing my tests to fail!


and value_ env parent t =
let open Value in
Expand Down
14 changes: 13 additions & 1 deletion src/xref2/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,19 @@ let module_of_unit : Odoc_model.Lang.Compilation_unit.t -> Component.Module.t =
in
let ty = Component.Of_Lang.(module_ empty m) in
ty
| Pack _ -> failwith "Unsupported"
| Pack _p ->
let m =
Odoc_model.Lang.Module.
{
id = (unit.id :> Odoc_model.Paths.Identifier.Module.t);
doc = unit.doc;
type_ = ModuleType (Signature []);
canonical = None;
hidden = unit.hidden;
}
in
let ty = Component.Of_Lang.(module_ empty m) in
ty

let lookup_root_module name env =
let result =
Expand Down
2 changes: 1 addition & 1 deletion src/xref2/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ and content env id =
let open Compilation_unit in
function
| Module m -> Module (signature env (id :> Id.Signature.t) m)
| Pack _ -> failwith "Unhandled content"
| Pack p -> Pack p

and value_ env parent t =
let open Value in
Expand Down