diff --git a/src/rustbook/build.rs b/src/rustbook/build.rs index 47bdc9335c401..31c973214a1c9 100644 --- a/src/rustbook/build.rs +++ b/src/rustbook/build.rs @@ -37,27 +37,34 @@ pub fn parse_cmd(name: &str) -> Option> { } } -fn write_toc(book: &Book, path_to_root: &Path, out: &mut Write) -> io::Result<()> { +fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Result<()> { fn walk_items(items: &[BookItem], section: &str, - path_to_root: &Path, + current_page: &BookItem, out: &mut Write) -> io::Result<()> { for (i, item) in items.iter().enumerate() { - try!(walk_item(item, &format!("{}{}.", section, i + 1)[..], path_to_root, out)); + try!(walk_item(item, &format!("{}{}.", section, i + 1)[..], current_page, out)); } Ok(()) } fn walk_item(item: &BookItem, section: &str, - path_to_root: &Path, + current_page: &BookItem, out: &mut Write) -> io::Result<()> { - try!(writeln!(out, "
  • {} {}", - path_to_root.join(&item.path.with_extension("html")).display(), + let class_string = if item.path == current_page.path { + "class='active'" + } else { + "" + }; + + try!(writeln!(out, "
  • {} {}", + class_string, + item.path_to_root.join(&item.path.with_extension("html")).display(), section, item.title)); if !item.children.is_empty() { try!(writeln!(out, "")); } try!(writeln!(out, "
  • ")); @@ -67,7 +74,7 @@ fn write_toc(book: &Book, path_to_root: &Path, out: &mut Write) -> io::Result<() try!(writeln!(out, "
    ")); try!(writeln!(out, "")); try!(writeln!(out, "
    ")); @@ -115,7 +122,7 @@ fn render(book: &Book, tgt: &Path) -> CliResult<()> { "#)); - let _ = write_toc(book, &item.path_to_root, &mut toc); + let _ = write_toc(book, &item, &mut toc); try!(writeln!(&mut toc, "
    ")); try!(writeln!(&mut toc, "
    ")); } diff --git a/src/rustbook/css.rs b/src/rustbook/css.rs index a5192eefd57ba..aae5f21a73dc6 100644 --- a/src/rustbook/css.rs +++ b/src/rustbook/css.rs @@ -97,6 +97,11 @@ body { color: #000000; } +.chapter li a.active { + text-decoration: underline; + font-weight: bold; +} + #toggle-nav { height: 20px; width: 30px;