Skip to content

Commit a40b758

Browse files
Use markdown::render instead of using pulldown_cmark directly
1 parent f7c8258 commit a40b758

File tree

5 files changed

+45
-49
lines changed

5 files changed

+45
-49
lines changed

src/bootstrap/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ impl<'a> Builder<'a> {
714714
"build" => self.cargo_out(compiler, mode, target),
715715

716716
// This is the intended out directory for crate documentation.
717-
"doc" => self.crate_doc_out(target),
717+
"doc" | "rustdoc" => self.crate_doc_out(target),
718718

719719
_ => self.stage_out(compiler, mode),
720720
};
@@ -743,7 +743,7 @@ impl<'a> Builder<'a> {
743743
_ => compile::librustc_stamp(self, cmp, target),
744744
};
745745

746-
if cmd == "doc" {
746+
if cmd == "doc" || cmd == "rustdoc" {
747747
if mode == Mode::Rustc || mode == Mode::ToolRustc || mode == Mode::Codegen {
748748
// This is the intended out directory for compiler documentation.
749749
my_out = self.compiler_doc_out(target);
@@ -883,7 +883,7 @@ impl<'a> Builder<'a> {
883883
.env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc"))
884884
.env(
885885
"RUSTDOC_REAL",
886-
if cmd == "doc" || (cmd == "test" && want_rustdoc) {
886+
if cmd == "doc" || cmd == "rustdoc" || (cmd == "test" && want_rustdoc) {
887887
self.rustdoc(compiler.host)
888888
} else {
889889
PathBuf::from("/path/to/nowhere/rustdoc/not/required")

src/bootstrap/doc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,15 @@ impl Step for Standalone {
405405
cmd.arg("--html-after-content").arg(&footer)
406406
.arg("--html-before-content").arg(&version_info)
407407
.arg("--html-in-header").arg(&favicon)
408+
.arg("--markdown-no-toc")
408409
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"))
409410
.arg("--markdown-playground-url")
410411
.arg("https://play.rust-lang.org/")
411412
.arg("-o").arg(&out)
412413
.arg(&path);
413414

414415
if filename == "not_found.md" {
415-
cmd.arg("--markdown-no-toc")
416-
.arg("--markdown-css")
416+
cmd.arg("--markdown-css")
417417
.arg("https://doc.rust-lang.org/rust.css");
418418
} else {
419419
cmd.arg("--markdown-css").arg("rust.css");
@@ -481,6 +481,7 @@ impl Step for Std {
481481
// will also directly handle merging.
482482
let my_out = builder.crate_doc_out(target);
483483
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
484+
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
484485

485486
let run_cargo_rustdoc_for = |package: &str| {
486487
let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
@@ -495,7 +496,9 @@ impl Step for Std {
495496
// FIXME: Cargo should probably do this itself.
496497
t!(fs::create_dir_all(out_dir.join(package)));
497498
cargo.arg("--")
498-
.arg("index-page").arg(&builder.src.join("src/doc/index.md"));
499+
.arg("--markdown-css").arg("rust.css")
500+
.arg("--markdown-no-toc")
501+
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
499502

500503
builder.run(&mut cargo);
501504
builder.cp_r(&my_out, &out);

src/librustdoc/html/render.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ use std::rc::Rc;
5454

5555
use externalfiles::ExternalHtml;
5656

57+
use errors;
58+
use getopts;
59+
5760
use serialize::json::{ToJson, Json, as_json};
5861
use syntax::ast;
5962
use syntax::ext::base::MacroKind;
@@ -80,8 +83,6 @@ use html::{highlight, layout};
8083

8184
use minifier;
8285

83-
use pulldown_cmark;
84-
8586
/// A pair of name and its optional document.
8687
pub type NameDoc = (String, Option<String>);
8788

@@ -508,6 +509,8 @@ pub fn run(mut krate: clean::Crate,
508509
id_map: IdMap,
509510
enable_index_page: bool,
510511
index_page: Option<PathBuf>,
512+
matches: &getopts::Matches,
513+
diag: &errors::Handler,
511514
) -> Result<(), Error> {
512515
let src_root = match krate.src {
513516
FileName::Real(ref p) => match p.parent() {
@@ -675,7 +678,7 @@ pub fn run(mut krate: clean::Crate,
675678
CACHE_KEY.with(|v| *v.borrow_mut() = cache.clone());
676679
CURRENT_LOCATION_KEY.with(|s| s.borrow_mut().clear());
677680

678-
write_shared(&cx, &krate, &*cache, index, enable_minification)?;
681+
write_shared(&cx, &krate, &*cache, index, enable_minification, matches, diag)?;
679682

680683
// And finally render the whole crate's documentation
681684
cx.krate(krate)
@@ -751,11 +754,15 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
751754
Json::Object(crate_data))
752755
}
753756

754-
fn write_shared(cx: &Context,
755-
krate: &clean::Crate,
756-
cache: &Cache,
757-
search_index: String,
758-
enable_minification: bool) -> Result<(), Error> {
757+
fn write_shared(
758+
cx: &Context,
759+
krate: &clean::Crate,
760+
cache: &Cache,
761+
search_index: String,
762+
enable_minification: bool,
763+
matches: &getopts::Matches,
764+
diag: &errors::Handler,
765+
) -> Result<(), Error> {
759766
// Write out the shared files. Note that these are shared among all rustdoc
760767
// docs placed in the output directory, so this needs to be a synchronized
761768
// operation with respect to all other rustdocs running around.
@@ -983,30 +990,15 @@ themePicker.onblur = handleThemeButtonsBlur;
983990
}
984991
try_err!(writeln!(&mut w, "initSearch(searchIndex);"), &dst);
985992

986-
<<<<<<< HEAD
987-
if cx.disable_index_page == false {
988-
let dst = cx.dst.join("index.html");
989-
=======
990993
if cx.enable_index_page == true {
991-
>>>>>>> a2642cf... f
992994
if let Some(ref index_page) = cx.index_page {
993-
let mut content = Vec::with_capacity(100000);
994-
995-
let mut f = try_err!(File::open(&index_page), &index_page);
996-
try_err!(f.read_to_end(&mut content), &index_page);
997-
let content = match String::from_utf8(content) {
998-
Ok(c) => c,
999-
Err(_) => return Err(Error::new(
1000-
io::Error::new(
1001-
io::ErrorKind::Other, "invalid markdown"),
1002-
&index_page)),
1003-
};
1004-
let parser = pulldown_cmark::Parser::new(&content);
1005-
let mut html_buf = String::new();
1006-
pulldown_cmark::html::push_html(&mut html_buf, parser);
1007-
let mut f = try_err!(File::create(&dst), &dst);
1008-
try_err!(f.write_all(html_buf.as_bytes()), &dst);
995+
::markdown::render(index_page,
996+
cx.dst.clone(),
997+
&matches, &(*cx.shared).layout.external_html,
998+
!matches.opt_present("markdown-no-toc"),
999+
diag);
10091000
} else {
1001+
let dst = cx.dst.join("index.html");
10101002
let mut w = BufWriter::new(try_err!(File::create(&dst), &dst));
10111003
let page = layout::Page {
10121004
title: "Index of crates",

src/librustdoc/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ fn main_args(args: &[String]) -> isize {
462462
diag.struct_err("too many file operands").emit();
463463
return 1;
464464
}
465-
let input = &matches.free[0];
465+
let input = matches.free[0].clone();
466466

467467
let mut libs = SearchPaths::new();
468468
for s in &matches.opt_strs("L") {
@@ -490,7 +490,7 @@ fn main_args(args: &[String]) -> isize {
490490
.collect();
491491

492492
let should_test = matches.opt_present("test");
493-
let markdown_input = Path::new(input).extension()
493+
let markdown_input = Path::new(&input).extension()
494494
.map_or(false, |e| e == "md" || e == "markdown");
495495

496496
let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
@@ -568,14 +568,14 @@ fn main_args(args: &[String]) -> isize {
568568

569569
match (should_test, markdown_input) {
570570
(true, true) => {
571-
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot,
571+
return markdown::test(&input, cfgs, libs, externs, test_args, maybe_sysroot,
572572
display_warnings, linker, edition, cg, &diag)
573573
}
574574
(true, false) => {
575-
return test::run(Path::new(input), cfgs, libs, externs, test_args, crate_name,
575+
return test::run(Path::new(&input), cfgs, libs, externs, test_args, crate_name,
576576
maybe_sysroot, display_warnings, linker, edition, cg)
577577
}
578-
(false, true) => return markdown::render(Path::new(input),
578+
(false, true) => return markdown::render(Path::new(&input),
579579
output.unwrap_or(PathBuf::from("doc")),
580580
&matches, &external_html,
581581
!matches.opt_present("markdown-no-toc"), &diag),
@@ -584,8 +584,8 @@ fn main_args(args: &[String]) -> isize {
584584

585585
let output_format = matches.opt_str("w");
586586

587-
let res = acquire_input(PathBuf::from(input), externs, edition, cg, &matches, error_format,
588-
move |out| {
587+
let res = acquire_input(PathBuf::from(input), externs, edition, cg, matches, error_format,
588+
move |out, matches| {
589589
let Output { krate, passes, renderinfo } = out;
590590
let diag = core::new_handler(error_format, None, treat_err_as_bug, ui_testing);
591591
info!("going to format");
@@ -624,11 +624,11 @@ fn acquire_input<R, F>(input: PathBuf,
624624
externs: Externs,
625625
edition: Edition,
626626
cg: CodegenOptions,
627-
matches: &getopts::Matches,
627+
matches: getopts::Matches,
628628
error_format: ErrorOutputType,
629629
f: F)
630630
-> Result<R, String>
631-
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
631+
where R: 'static + Send, F: 'static + Send + FnOnce(Output, &getopts::Matches) -> R {
632632
match matches.opt_str("r").as_ref().map(|s| &**s) {
633633
Some("rust") => Ok(rust_input(input, externs, edition, cg, matches, error_format, f)),
634634
Some(s) => Err(format!("unknown input format: {}", s)),
@@ -682,11 +682,11 @@ fn rust_input<R, F>(cratefile: PathBuf,
682682
externs: Externs,
683683
edition: Edition,
684684
cg: CodegenOptions,
685-
matches: &getopts::Matches,
685+
matches: getopts::Matches,
686686
error_format: ErrorOutputType,
687687
f: F) -> R
688688
where R: 'static + Send,
689-
F: 'static + Send + FnOnce(Output) -> R
689+
F: 'static + Send + FnOnce(Output, &getopts::Matches) -> R
690690
{
691691
let default_passes = if matches.opt_present("no-defaults") {
692692
passes::DefaultPassOption::None
@@ -731,7 +731,7 @@ where R: 'static + Send,
731731
*x == "ui-testing"
732732
});
733733

734-
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
734+
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(&matches, error_format);
735735

736736
let (tx, rx) = channel();
737737

@@ -783,7 +783,8 @@ where R: 'static + Send,
783783
krate = pass(krate);
784784
}
785785

786-
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
786+
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes },
787+
&matches)).unwrap();
787788
}));
788789

789790
match result {

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn render(input: &Path, mut output: PathBuf, matches: &getopts::Matches,
7777
diag.struct_err(&format!("{}: {}", output.display(), e)).emit();
7878
return 4;
7979
}
80-
Ok(f) => f
80+
Ok(f) => f,
8181
};
8282

8383
let (metadata, text) = extract_leading_metadata(&input_str);

0 commit comments

Comments
 (0)