Skip to content

initial work for cargo doc for markdown #2256

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub fn doc(manifest_path: &Path,
}

try!(ops::compile(manifest_path, &options.compile_opts));
try!(build_markdown_docs(manifest_path));

if options.open_result {
let name = if options.compile_opts.spec.len() > 1 {
Expand All @@ -60,6 +61,47 @@ pub fn doc(manifest_path: &Path,
Ok(())
}

fn build_markdown_docs(manifest_path: &Path) -> CargoResult<()> {
let docs_dir = if let Some(dir) = manifest_path.parent() {
dir.join("doc")
} else {
return Ok(());
};

let target_dir = if let Some(dir) = manifest_path.parent() {
dir.join("target/doc")
} else {
return Ok(());
};

try!(fs::create_dir_all(&target_dir));

for entry in try!(fs::read_dir(docs_dir)) {
let entry = try!(entry);
let path = entry.path();

let extension = match path.extension() {
Some(e) => e,
None => continue,
};

if "md" == extension {
println!("let's do this: {:?}", path);
let output_result = Command::new("rustdoc")
.arg(&path)
.arg("-otarget/doc")
.output();
let output = try!(output_result);

if !output.status.success() {
println!("failed");
}
}
}

Ok(())
}

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
fn open_docs(path: &Path) {
// trying xdg-open
Expand Down