-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Medias in odoc #1005
Medias in odoc #1005
Conversation
dcd0b24
to
41e2c5b
Compare
src/document/comment.ml
Outdated
| Error exn -> | ||
(* FIXME: better error message *) | ||
Printf.eprintf "Id.href failed: %S\n%!" | ||
(Url.Error.to_string exn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like: "Can't resolve asset file path/url"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's taken from a "warning" thrown in similar situations.
However, yes, we could finally fix those FIXME
instead of propagating them through the code...
Related: #1010 which removed similar unconditional eprintfs.
@@ -90,6 +94,9 @@ and Block : sig | |||
| Verbatim of string | |||
| Raw_markup of Raw_markup.t | |||
| Table of t Table.t | |||
| Image of Target.t * Inline.t | |||
| Video of Target.t * Inline.t | |||
| Audio of Target.t * Inline.t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 3 implementations is very similar, what do you think of using something similar to the model:
type media = [ `Image | `Audio | `Video ]
type t =
...
| Media of media * Target.t * Inline.t
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both implementations are very similar but I can try to see if it can make some part of the code more factorized!
That seems rather limiting. I don't really care about the inline bit but you definitively want to put these things into lists, for example:
I don't really care if the assets element ends up being a block level element rather than an inline but I definitively want it into list elements. |
I'm in favor of medias to be (nestable) block elements. These elements take time to show up and might never do. I think it's important to make sure they are visible, for example by nesting them in a block with a border and a large padding. |
41e2c5b
to
75d5830
Compare
I turned medias into nestable block elements: it is now possible to add them inside lists and tables. |
4fa1ec4
to
76071aa
Compare
@@ -349,7 +349,7 @@ module L = struct | |||
when name = LabelName.to_string name' -> | |||
Ok (`Identifier label) | |||
| _ -> find tl) | |||
| [] -> Error (`Find_by_name (`Page, name)) | |||
| [] -> Error (`Find_by_name (`Label, name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a fix that could be made in a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it could be made in another PR. Not sure that's worth it, given how small it is! But if anyone confirm it's helpful, I'll separate it into another PR!
image url | ||
| Internal Unresolved -> | ||
let a = [ Html.a_class [ "xref-unresolved" ] ] in | ||
[ Html.span ~a (inline ~config ~resolve alt) ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there is no alt text, yes that's a good idea! (are we allowed to use this particular image?)
When there is alt text, I'm not sure what's best!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think it's better to let things break. This makes it mechanically discoverable (404) if you add a stub, then the page has no problem as far as machines are concerned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readers also need to distinguish missing images. Perhaps the alt text could be made mandatory ?
That's what I was most worried about when I suggested to add border, padding and a caption around image blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readers also need to distinguish missing images.
Browsers already have their own way of notifying users about broken image sources (typically via a small icon representing a broken document), there's no need to invent anything here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah but of course this should not be an a
this should be an img
tag with the class xref-unresolved
and perhaps with the src
attribute being simply the undefined reference (so that the broken icon shows up, it does not with an empty src
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it's a span
(the a
is for attribute) which include visual feedback that something is wrong, but nothing tells the user or the browser that an image should be there. So yes, I think an img
with broken url and the alt text as alt text (if there is one) makes sense.
I'll check if "broken url" can be made a real concept, and how the browser react!
Here is the state of this PR! It is mostly finished, I think. There is one remaining question: what do we do with unresolved medias. @dbuenzli suggested to use an "unresolved" URL, so that the browser is responsible for showing the breakage. I have tested how my browser (firefox) displays an image with an url that returns 404. When there is no alt text, it shows an icon of a broken image. When there is an empty alt-text, it shows nothing. When there is a non-empty alt-text, it shows the alt-text as an image. All of this is a very good behaviour in my opinion. Also, to note, I have tried some "invalid" urls, such as I won't have time to work on this more in the coming month. |
In fact I forgot that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few typos left in the code.
Otherwise, it looks good to me, is something else missing or blocking this PR?
src/parser/ast.ml
Outdated
reference_kind | ||
* media_href with_location | ||
* inline_element with_location list | ||
* media (** @since 2.3.0 *)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably 2.4.0
?
@@ -729,26 +770,55 @@ let resolve_reference_dot env parent name = | |||
| (`C _ | `CT _) as p -> resolve_reference_dot_class env p name | |||
| `P _ as page -> resolve_reference_dot_page env page name | |||
|
|||
let resolve_page_reference env (r : Reference.Page.t) = | |||
match r with | |||
| `Resolved _ -> failwith "unimplemented" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not forget this
Yes, I'd just like to try the suggestion in #1002 before we merge that, then this can be rebased on top. |
I have a related request which I believe will come up once this PR is merged: I hope there's a way for odoc to download external images, audios, and maybe videos and generate offline-viewable pages. The reason is that I might want to generate a self-contained documentation site for offline reading without putting everything in the same git repo. Maybe this can be done in a different PR, but I hope the current design is compatible with this request. |
Reference can now be toward assets. When resolving them, look up the assets of the current page, and if not found, recurse in the parent page. Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
14a8c2f
to
39de6d2
Compare
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
ef077e3
to
4e40617
Compare
Signed-off-by: Paul-Elliot <[email protected]>
Co-authored-by: Guillaume Petiot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Closing now since asset referencing will change subsequently soon. But some of the code will be used! |
Based on #1002.
See #985 for discussion about the syntax.
The syntax
The syntax is the following, where
<media>
can be eitherimage
,video
oraudio
:The media elements are block elements, and as such should be separated from the rest of the content with new lines.
They cannot be put inline (so, for now, no
{{:link-to-something}{image!ref}}
...) or even inside other block elements (such as table, lists, ...).The reason for this is that without attributes (e.g. to define the size) it would be quite hard to style the inserted media as an inline in a consistent way...
I think it is enough for most cases. Searching github for
{html%
and embedding of images seems to comfort this.The rendering
Only html display medias, using the html5 elements
audio
,video
andimg
. Even images are not displayed in latex (it lacks "asset" support).For images, the "replacement text" is used an alt text. The replacement text is also used in case of unresolved reference.
For latex and manpage backend, the replacement text is always used.
Future work
I wondered whether something such as
{href!reference.to."asset.png"}
, which would render as../../reference/to/asset.png
(for instance) would be a good addition? It would allow more html embedding, such as{html% <img src="%}{href!ref}{html%"/>%}
.What do you think?
Having a way to specify the size (but this requires some syntax discussion!), or to add inline media, would be nice.