odoc icon indicating copy to clipboard operation
odoc copied to clipboard

`odoc html` allow to specify the base URI for resolving links to external identifiers.

Open dbuenzli opened this issue 8 years ago • 11 comments

When you develop your package locally you'd like to be able to generate its documentation in its say _build directory but also to check the accuracy of external links against the current switch docs.

For this we need an option to specify the base URI to use for resolving links to other packages (typically this base uri will be a relative file path to $(opkg cache path)/odoc).

dbuenzli avatar Sep 26 '16 13:09 dbuenzli

@aantron during your refactoring did you have time to consider this ?

dbuenzli avatar Apr 20 '18 08:04 dbuenzli

No, I didn't explicitly consider this. It should be possible to add with some effort, though. I think my refactoring was mostly orthogonal to this issue.

aantron avatar Apr 20 '18 19:04 aantron

Ok thanks for the answer. I don't think this is a complex problem as long as you carefully isolate the functions that generate links. It would be nice to have though so that you can properly test inter-package links.

dbuenzli avatar Apr 23 '18 14:04 dbuenzli

Things don't seem to have changed to much in that area during the reorganization, and it should indeed be relatively easy to change from what I can see.

trefis avatar Apr 23 '18 14:04 trefis

I'm considering implementing this feature. What would be the best place to start? Any pointers would be very appreciated as, given the current implementation, I don't see a clean and easy way to parametrise the base URI. The code base seems to pervasively assume that there's a root package.

This is needed to implement HTML fragments that don't belong to a particular package and can set the root to the docsets path for cross-reference resolution. See https://github.com/ocaml/odoc/pull/166#issuecomment-415421238 for more details.

rizo avatar Aug 23 '18 17:08 rizo

@dbuenzli Can we decide the interface for this feature? I might be able to implement partial support for fragments.

It seems like if I intercept the Html.Html_tree.Relative_link.Id.href function call during HTML generation I can supply a custom base URI.

What about?

$ odoc html-fragment --root-uri=URI -o FRAGMENT.html -I INCLUDE_DIR PAGE.mld

This is for the html-fragment, we could add it later to other commands too.

rizo avatar Aug 23 '18 17:08 rizo

As a side note (and to remind myself), it would be useful if this option could be integrated with dune when it's done.

rizo avatar Aug 23 '18 18:08 rizo

Update: I implemented a limited support for the --root-uri option for the proposed html-fragment command in https://github.com/ocaml/odoc/pull/166/commits/71f4a3e7e9cbc477130b697bd46015254d630d72. Still need to polish some things, but feedback is welcome!

rizo avatar Aug 23 '18 18:08 rizo

Great ! I'm a little bit unsure about the --root-uri name though, when I read the cli it seems to me that it defines the root of the generated document and that's not the case, it defines the URI w.r.t. to which cross-references are resolved in the resulting document. Maybe --xref-root-uri or --xref-base-uri or --xref-uri ?

dbuenzli avatar Aug 24 '18 06:08 dbuenzli

Update: This is partially solved by https://github.com/ocaml/odoc/pull/166, i.e., the odoc html-fragment command accepts the --root-uri option. This is not implemented for the odoc html command yet. I'll try to implement this later when other more critical issues are solved.

@dbuenzli sorry I forgot about your suggestion to change the name of --root-uri in my fragment PR. Would you like me to change it to one of your options? Which one?

rizo avatar Oct 08 '18 14:10 rizo

Pick the one you prefer but I think the one that is maybe the most terminology correct is --xref-base-uri.

dbuenzli avatar Oct 08 '18 14:10 dbuenzli