-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Include images in rustdoc output #32104
Comments
I second this, images can greatly help explaining (geometrical split_at example). |
Since the focus is on doxidize now, rustdoc is in maintenance-only mode. Should this be closed? cc: @steveklabnik |
I'd say "maintenance-only" mode is a bit strong; |
Would love this as well! Has there been any updates? |
It‘s work
|
That only works locally if you're building the docs for your own crate. Does not work on docs.rs or if the crate is a dependency of something else. Background: |
@crepererum you're right. One solution is to separate the doc file and manually modify it. |
Or you host the image somewhere, like on GitHub pages (that's what ndarray is doing here https://github.com/rust-ndarray/ndarray/blob/master/src/impl_views.rs ) |
I think what would be most optimal is if there could be a folder where images for the doc could be stored in the crate folder structure. There is one huge painpoint here though, and that is a lot of people just love to generate extremely large pictures to include in the crates. For no reason: ClickBait article with example So if this should be in the code, the file size should be limited. |
There is a workaround. You can insert the image data, base64 encoded, directly into your rust source code comments, http://www.bigfastblog.com/embed-base64-encoded-images-inline-in-html $ base64 ../images/mypicture.png | awk ' { print "/// " $1 } ' > myfile.b64 myfile.rs:
/// my function does blah blah blah. here is a picture:
/// <div>
/// <img src="data:image/png;base64,
/// iVBORw0KGgetcetcetc <-- copy/paste myfile.b64 here
/// .... <-- several dozen lines of myfile.b64
/// JDIOIDondio00778== <-- last line of myfile.b64
/// ">
/// </div>
fn myfunction(x:u64)->bool { x<5 } $ cargo doc Now the html file under target/whatever will have the png image baked inside of it as base64 code. I think this might be possible with svg but havent tested. I think it might be nice to consider if rustdoc could do this on it's own, automatically, taking a |
I don't think this is a good idea: it'd force rustdoc to download the content to know if it's an image or a video or anything else. Also, from a security perspective, I think this wouldd be an issue as well (cc @pietroalbini ). |
From my point of view it'd be fine if rustdoc included images present in the crate's source tarball into the generated docs. It definitely should not download images from the Internet. |
I don't see the difference between local image and one from the internet. In both case, it can't be trusted. |
Well then, I am guessing the current way to input it into a comment as base64 isnt much different. The end result should still be an image shown online, wherever it is a link to an image, or an image generated from base64. Nothing can be trusted anywhere, but still we do it. |
You can do the same thing with workarounds today, and you'll still be able to do it with workarounds in the future. Besides, it's a legit feature request. |
Indeed, I don't know why but I was kinda confusing the URL thing... Then yes, it'll require to move the file content to a given target and be sure to not have conflicts. Urg... Headache ahead! I'll try to do it in not too long from now. |
A possible solution for this would be to hash the image content, move them to |
If I hash the path, it might be easier, indeed. I didn't want to create another folder but that would fix the naming conflict so I think I'll do that. Thanks for the tips! |
I would rather hash the file content than the path, since the same file might be referred to by different .rs files, using different paths. |
With this feature, would it also be possible to link to a file included in the crate inside the |
I ran into this today and would love to see it happen. @GuillaumeGomez is this something I could help with? I've never contributed to rustdoc before but if you'd be interested in mentoring me maybe I could help implement it? |
|
The documentation is here. |
@GuillaumeGomez: that's very interesting! I was led to believe otherwise by the following sentence in the unstable book (see link above): I couldn't find out when While this EDIT: It would however lead to an improvement in the sense that no doc-related code is generated for non-doc builds, other than having to build the dependencies. |
No even though there is an open issue about that on cargo. But it hasn't received much attention unfortunately. As for |
And here is the cargo issue. |
I opened an RFC for this feature: rust-lang/rfcs#3397 |
Our architecture diagram is broken if you run `cargo doc`. I looked into it. It seems that it's hard to put images into Rustdoc (see [rust-lang/rust#32104]). You can do it with absolute URLs that point to some fixed HTTPS location, you can hack things up with helpers so that images get recoded into data: URLs, and a few other strategies. But our architecture diagram can work OK in ascii art, and that doesn't require any extra hacks, so here's what I've got. Signed-off-by: Ben Pfaff <blp@feldera.com>
Our architecture diagram is broken if you run `cargo doc`. I looked into it. It seems that it's hard to put images into Rustdoc (see [rust-lang/rust#32104]). You can do it with absolute URLs that point to some fixed HTTPS location, you can hack things up with helpers so that images get recoded into data: URLs, and a few other strategies. But our architecture diagram can work OK in ascii art, and that doesn't require any extra hacks, so here's what I've got. Signed-off-by: Ben Pfaff <blp@feldera.com>
Our architecture diagram is broken if you run `cargo doc`. I looked into it. It seems that it's hard to put images into Rustdoc (see [rust-lang/rust#32104]). You can do it with absolute URLs that point to some fixed HTTPS location, you can hack things up with helpers so that images get recoded into data: URLs, and a few other strategies. But our architecture diagram can work OK in ascii art, and that doesn't require any extra hacks, so here's what I've got. Signed-off-by: Ben Pfaff <blp@feldera.com>
# Objective This PR continues #8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
# Objective This PR continues #8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
This is how I did it in Github Actions, not complicated, might not be worth a full RFC. However, it would be nice if rustdoc could do this natively so it could check if the image link is valid. https://github.com/ryanpeach/OrbitingSandRust/pull/102 |
Sure, it works in your CI, but how does it work for crates depending on yours? Are your images included into your crate package? If so you're doing something very wrong. |
Just including my PR so that others looking for a more immediate solution who find this on google can see an example. |
Is there a particular issue with including images in a crate package besides size? |
Not that I can think of. The RFC is currently on hold until the potential cargo archive format becomes a reality (as mentioned here). |
@GuillaumeGomez So if this is the only way to do it, then why is it "very wrong"? |
I answered (too aggressively) to:
In particular this part:
The fact that we might includes megabytes (if not more) of data by default only for documentation sounds like something that should be very carefully considered. |
# Objective This PR continues bevyengine/bevy#8885 It aims to improve the `Mesh` documentation in the following ways: - Put everything at the "top level" instead of the "impl". - Explain better what is a Mesh, how it can be created, and that it can be edited. - Explain it can be used with a `Material`, and mention `StandardMaterial`, `PbrBundle`, `ColorMaterial`, and `ColorMesh2dBundle` since those cover most cases - Mention the glTF/Bevy vocabulary discrepancy for "Mesh" - Add an image for the example - Various nitpicky modifications ## Note - The image I added is 90.3ko which I think is small enough? - Since rustdoc doesn't allow cross-reference not in dependencies of a subcrate [yet](rust-lang/rust#74481), I have a lot of backtick references that are not links :( - Since rustdoc doesn't allow linking to code in the crate (?) I put link to github directly. - Since rustdoc doesn't allow embed images in doc [yet](rust-lang/rust#32104), maybe [soon](rust-lang/rfcs#3397), I had to put only a link to the image. I don't think it's worth adding [embed_doc_image](https://docs.rs/embed-doc-image/latest/embed_doc_image/) as a dependency for this.
As written by Luthaf over here
https://users.rust-lang.org/t/include-images-in-rustdoc-output/3487
"Hi rustaceans!
Images in documentation can be really useful to provide some insight on algorithms or modules organisation.
It is already possible to insert a link to an image in documentation comment
But using this method, we only get to include images already available in some place of Internet.
Is it a way to make rustdoc copy some files to the target/doc folder, so that it is easy to include specific images in the documentation? The same could go for other static files, like specific CSS or JS.
Is it possible yet? If not, do you think it is worth it?"
I this this would be awesome to include as sometimes using images is much easier when explain something than showing text.
The text was updated successfully, but these errors were encountered: