-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Allow html in crate docs. #15237
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
Allow html in crate docs. #15237
Conversation
FWIW, this isn't allowing markdown, this is allowing HTML to be included inline. Could you update the commit message? |
@@ -41,6 +41,10 @@ use std::str; | |||
use std::string::String; | |||
use std::sync::Arc; | |||
|
|||
use getopts::Matches; | |||
|
|||
use super::super::markdown::load_external_files; |
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.
This can just be use markdown::load_external_files;
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.
How so? I'm using the fn from src/librustdoc/markdown. Don't I need this to differentiate it?
Also, to dive a bit deeper, I wanted to avoid copy-pasting this function when it was available in another module but, in doing so, I've made it publicly available through the rustdoc crate. Is that OK? Should I, instead of using use statements, simply be copying the source of this function (and the macro/function it depends on) to the render.rs file?
I tend to think this should be refactored to avoid exposing it unnecessarilly.
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.
imports are relative to the root of the crate by default (equivalent to /...
in a file system) and markdown
is declared at the root. The relative import works, but it's not necessary. (This is like being in a directory /html/render
and accessing /markdown/load_external_files
via ../../markdown/load_external_files
but instead /markdown/load_external_files
works and is simpler.)
Also, to dive a bit deeper, I wanted to avoid copy-pasting this function when it was available in another module but, in doing so, I've made it publicly available through the rustdoc crate. Is that OK?
Yes, but it would be nice to avoid it.
Should I, instead of using use statements, simply be copying the source of this function (and the macro/function it depends on) to the render.rs file?
No definitely not.
I tend to think this should be refactored to avoid exposing it unnecessarily.
Yep, my longer comment on the PR itself addresses by putting the loading into one place.
Thanks for doing this work! Unfortunately there's ways in which this can be improved:
In markdown.rs (it should probably move elsewhere, but I'm not sure the best way to manage it... maybe move pub struct ExternalHtml {
pub in_header: String,
pub before_content: String,
pub after_content: String
}
impl ExternalHtml {
pub fn load(in_header: &[String], before_content: &[String],
after_content: &[String]) -> Option<ExternalHtml> {
match (load_external_files(in_header),
load_external_files(before_content),
load_external_files(after_content)) {
(Some(ih), Some(bc), Some(ac)) => {
Some(ExternalHtml {
in_header: ih,
before_content: bc,
after_content: ac
})
}
_ => None
}
}
}
...
pub fn render(..., external_html: &ExternalHtml) { ... In use markdown::ExternalHtml;
// ...
// possibly on on L178
let external_files = match ExternalHtml::load(matches.opt_strs("html-in-header").as_slice(),
matches.opt_strs("html-before-content").as_slice(),
matches.opt_strs("html-after-content").as_slice()) {
Some(ef) => ef,
None => return 3,
};
// ...
(false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")),
&matches, &external_html),
// ...
match html::render::run(krate, output.unwrap_or(Path::new("doc")), &external_html) {
// ... Then If you have any questions, just ask (here or IRC (huon)). |
I just responded to all your line comments, only to see that you had the same concerns when I finally got to your final comment :) I'll go over this more thoroughly tomorrow, and I'll be sure to reach out if I have more questions. |
If you could, it would be good to update them ( (At the very least, you should change the argument names in |
I can do them when I fix everything else up. I really just could not find them. |
@huonw, I believe I've changed everything discussed. This exposes more of rustdoc, in exposing functions and a macro that convert an array of strings (filepaths) to a string. It is in the I've also changed how the header/footer are generated. There are now explicit sections in all generated documentation for the header/footer, which are left blank if none are provided through the flags (but not removed from the DOM). They are given 0 padding in I can squash this into one commit, but wanted to leave it separate to make it easier to review. I can squash it if you'd like. |
|
||
#[deriving(Clone)] | ||
pub struct ExternalHtml{ | ||
pub in_header: Option<String>, |
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.
These need to be String
with load
returning Option<ExternalHtml>
: None
represents an error, and so rustdoc should exit.
(See the code in my large comment.)
Updated documentation to reflect md->html. Modularized external file loading.
…, r=huonw This makes the `in-header`, `markdown-before-content`, and `markdown-after-content` options available to `rustdoc` when generating documentation for any crate. Before, these options were only available when creating documentation *from* markdown. Now, they are available when generating documentation from source. This also updates the `rustdoc -h` output to reflect these changes. It does not update the `man rustdoc` page, nor does it update the documentation in [the `rustdoc` manual](http://doc.rust-lang.org/rustdoc.html).
minor: Remove old section about downloading the server from the manual Closes rust-lang#15237
This makes the
in-header
,markdown-before-content
, andmarkdown-after-content
options available torustdoc
when generating documentation for any crate.Before, these options were only available when creating documentation from markdown. Now, they are available when generating documentation from source.
This also updates the
rustdoc -h
output to reflect these changes. It does not update theman rustdoc
page, nor does it update the documentation in therustdoc
manual.