Skip to content
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

cargo doc could support building/testing standalone markdown files #739

Open
huonw opened this issue Oct 22, 2014 · 38 comments
Open

cargo doc could support building/testing standalone markdown files #739

huonw opened this issue Oct 22, 2014 · 38 comments
Labels
Command-doc Command-test S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@huonw
Copy link
Member

huonw commented Oct 22, 2014

E.g. project specific guides/tutorials, like rust-lang/rust itself.

See also

@steveklabnik steveklabnik added the A-features Area: features — conditional compilation label Jul 27, 2015
@chriskrycho
Copy link

Right now, it appears that rust-lang/rust uses pandoc to build its docs. It seems like it would be nice to go ahead and get this moving forward so that dependency could be dropped. Two questions, therefore:

  1. What is the status on this? Has anything been done?
  2. What would need to be done to make it work?

@steveklabnik
Copy link
Member

I'm not aware of anything that's being done.

I don't actually think pandoc is used anymore, all that is stale.

@chriskrycho
Copy link

Ah, interesting. I'll go read the makefile; if nothing else I can submit a PR to update that.

@steveklabnik
Copy link
Member

I was editing but since you replied, I'll make it a new comment:

I don't actually think pandoc is used anymore, all that is stale. It was being used to generate PDF and EPUB, but we don't do that anymore.

You'd basically need a way to tell cargo to invoke rustdoc on MD files, wherever those are. I would suggest maybe a top-level doc directory that any doc/**/*.md gets rustdoc called on would make sense.

@chriskrycho
Copy link

One quick question about that: I assume you're meaning top-level doc relative to src, in line with the conventions in e.g. this repository? So a basic crate setup for Cargo would have something like:

/
  Cargo.toml
  README.md
  src/
    lib.rs
    and_modules/
    doc/
      some_stuff.md
      more_stuff.md

Or am I misreading you?

Also, would it make sense to include the README.md file if one is supplied—as the index, perhaps?

Fair warning: it'll probably take me at least a month to implement, if not more, but I'd like to give it a go. I'll probably be inhabiting #rust an awful lot on the weekends I work on it. 😛

@alexcrichton
Copy link
Member

I've thought about this a bit in the past, and the general idea is something like:

  1. On cargo doc, Cargo will automatically crawl /doc (in the project root) for *.md files
  2. Each markdown file will be passed through rustdoc and rendered, maintaining the same basic structure as the doc folder itself
  3. On cargo test Cargo will automatically run rustdoc --test over all markdown files

Feel free to reach out to me with any questions!

@chriskrycho
Copy link

@alexcrichton, very good.

The reason I was thinking to use /src/doc rather than /doc for the root was because both this repository and the main Rust repository both already have their docs there. As such, my guess was that a fair bit of the community may have their packages likewise structured (because my own first instinct for structuring a project is to check how large, official projects in a language do it). Obviously those can move, though,* and I'm happy to defer to you guys in any case. I'll plan for it to work basically as you outlined.

* I was also hesitant initially because I was remembering repository size problems problems with large moves in Mercurial, but that's not a pain point for Git, so.

@chriskrycho
Copy link

@alexcrichton and @steveklabnik, how should this interact with (including just ignoring it) rustbook?

@alexcrichton
Copy link
Member

I don't have super strong opinions about /src/doc vs just /doc, but I think we'd prefer to root everything in /doc as it seems to fit the conventions of other projects in other languages. The reason the compiler does this is that the top level /doc is actually where all the generated documentation goes. I... don't actually know why cargo does it!

I'm not currently aware of any conventions externally in the community about this, I wouldn't expect there to be too much buy in to either scheme just yet though.

I'm also fine just not worrying about rustbook for now, conventions can always be adapted!

@steveklabnik
Copy link
Member

Yeah, I feel the same as @alexcrichton, basically. Same with 'dont worry about Rustbook'.

@chriskrycho
Copy link

Excellent—just wanted to check that box before proceeding. I'll go ahead with the root docs directory! Hopefully starting in on it a bit this week(end).

bors added a commit to rust-lang/rust that referenced this issue Aug 13, 2015
…labnik

Per @steveklabnik's comment [here](rust-lang/cargo#739 (comment)), the Pandoc components of the Makefile are no longer used, and as such the corresponding components of the documentation are out of date.

  - I've removed the Pandoc (and therefore also LaTeX) elements of the makefile and confirmed that the build proceeds correctly.
  - I updated the documentation to reference `rustdoc` and  of Pandoc.

r? @steveklabnik
@SimonSapin
Copy link
Contributor

Would these generated HTML files (optionally?) include the crate index side bar and the search bar?

@chriskrycho
Copy link

chriskrycho commented Aug 28, 2015 via email

@SimonSapin
Copy link
Contributor

👍

@chriskrycho
Copy link

Just a quick update: I've spent several hours last week and expect to spend several more this weekend familiarizing myself with the way cargo doc currently works so that when I start implementing, it'll be in line with how things presently work.

@alexcrichton
Copy link
Member

@chriskrycho awesome! Feel free to ask any questions here or on IRC if you run into any speed bumps!

@ebkalderon
Copy link

Bump. Any progress on this @chriskrycho?

@chriskrycho
Copy link

chriskrycho commented Nov 19, 2015 via email

@steveklabnik
Copy link
Member

Just checking in: nobody has started work on this in the meantime, yeah? Maybe I should.

@chriskrycho
Copy link

chriskrycho commented Dec 30, 2015 via email

@hoodie
Copy link

hoodie commented Apr 11, 2016

Just as a consideration, how would we name these markdown files? Tread them the same way as .rs files so that I pub mod documentation for a documentation.rs? There are tones of projects on github that have Readme.md files in subdirectories. What about (when this is reopened) rustdoc automatically includes Readme.md files in module folders as module level documentation?

@hoodie
Copy link

hoodie commented Apr 11, 2016

@chriskrycho BTW: I would also love to see this take off, so if you want to collaboratively start working on this again? I'm in.

@steveklabnik
Copy link
Member

@hoodie in general, the idea would be that you'd write whatever.md and that will generate a whatever.html.

I'm skeptical of making readmes into module-level documentation, but possibly as an index.html.

@hoodie
Copy link

hoodie commented Apr 11, 2016

I though, only explicitly if the Readme.md is right next to a mod.rs, per se.

@lilith
Copy link
Contributor

lilith commented Nov 16, 2016

I'm a bit confused about what the docs mean regarding standalone markdown files if they're not referring to this feature. Am I missing something obvious?

@Michael-F-Bryan
Copy link

Michael-F-Bryan commented Nov 16, 2016

That's what I thought as well. I tried putting a markdown file in my src directory (with the % title line) and then running cargo doc, but it looks like cargo completely ignores the file.

Minimal example:

$ cd /tmp
$ cargo new dummy && cd dummy
$ cat > src/extra_docs.md << EOF
 % A Title           

 # Heading 1

 Lorem ipsum...
 EOF
$ cargo doc --open
$ find ./target/doc -name "*extra_docs*"

In this case I'd expect the extra_docs page to be compiled to html and then linked in with the rest of my documentation. You can compile markdown manually with rustdoc, which is probably what the documentation is referring to, but that won't link it in with the rest of your docs or apply any styling and cargo doesn't have any (easy) ways of including extra pages purely for documentation.

This was done using nightly rustc and cargo.

@drusellers
Copy link

https://www.reddit.com/r/rust/comments/5crpfy/announcing_cargo_externaldoc/

@steveklabnik
Copy link
Member

@nathanaeljones @Michael-F-Bryan those are the docs for rustdoc. Rustdoc can do this. cargo doc does not call rustdoc on markdown files. That's the core issue.

@JelteF
Copy link

JelteF commented Feb 11, 2017

cargo-external-doc is really nice. But it would be great to have this directly integrated into cargo. That way I can use docs.rs instead of hosting my docs on github.

@Zteve
Copy link

Zteve commented Feb 21, 2017

@alexcrichton I'm trying to build doc for a project atm; and not having the md files merged into the cargo generated documentation is a real pain. I don't want to use an add-on like cargo-external-doc if an integrated solution is forthcoming, but on the other hand the list of things you say you need before you can do that seems very daunting.

Is it really necessary to do all those things before you can simply reference the md files from the generated doc?

@alexcrichton
Copy link
Member

@Zteve I'd personally prefer a fully fleshed out implementation, yes. Half-baked implementations just get bugs opened against them and I usually end up personally having to fix them, which I'd ideally prefer to head off at the beginning.

@Zteve
Copy link

Zteve commented Feb 24, 2017

@alexcrichton Fair enough; sentiments I can relate to. Go to it, then :-D

@jamen
Copy link

jamen commented Feb 19, 2020

I came across this and #1016 after thinking of workspace documentation. It'd be nice to have doc/index.md when documenting all of the crates, or providing information the subject the project is about.

benesch added a commit to benesch/materialize that referenced this issue Feb 21, 2020
While we wait for rust-lang/cargo#739 to get
resolved, we hardcode the rustdoc template in bin/doc so that we can
generate a nice index page for our docs. This hardcoded template has
diverged a bit from rustdoc; update it to accordingly.
@benesch
Copy link
Contributor

benesch commented Feb 21, 2020

If you want a hacky shell/jq script to do that in the meantime, here's what we're using at @MaterializeInc:

https://github.com/MaterializeInc/materialize/blob/master/bin/doc
https://github.com/MaterializeInc/materialize/blob/master/misc/doc/crates.jq

@Carter12s
Copy link

Hey I'm interested in trying to tackle this! Caveat, first time attempting to contribute to cargo and this old of an issue is pretty intimidating. Reading the contributor's guide right now (what a great doc), and this issue is missing a lot of labels? Could likely use an area, feature accepted (if it is?), mentor maybe?

I'm planning to start reading up on this today, and will hopefully be able to post a design (or at least a list of questions) soon.

I have steve's work from 5 years ago as a bit of a start: #2256

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-doc Command-test S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
Status: No status
Development

No branches or pull requests