]> git.proxmox.com Git - rustc.git/blobdiff - vendor/mdbook/src/renderer/html_handlebars/helpers/toc.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / vendor / mdbook / src / renderer / html_handlebars / helpers / toc.rs
index 0884d30ad156a52696b621e2cce424cf6bd6340d..e96e6ef64839c3233e074fe61e0063c5dd30965c 100644 (file)
@@ -117,35 +117,35 @@ impl HelperDef for RenderToc {
             }
 
             // Link
-            let path_exists = if let Some(path) =
-                item.get("path")
-                    .and_then(|p| if p.is_empty() { None } else { Some(p) })
-            {
-                out.write("<a href=\"")?;
-
-                let tmp = Path::new(item.get("path").expect("Error: path should be Some(_)"))
-                    .with_extension("html")
-                    .to_str()
-                    .unwrap()
-                    // Hack for windows who tends to use `\` as separator instead of `/`
-                    .replace('\\', "/");
-
-                // Add link
-                out.write(&utils::fs::path_to_root(&current_path))?;
-                out.write(&tmp)?;
-                out.write("\"")?;
-
-                if path == &current_path || is_first_chapter {
-                    is_first_chapter = false;
-                    out.write(" class=\"active\"")?;
-                }
+            let path_exists: bool;
+            match item.get("path") {
+                Some(path) if !path.is_empty() => {
+                    out.write("<a href=\"")?;
+                    let tmp = Path::new(path)
+                        .with_extension("html")
+                        .to_str()
+                        .unwrap()
+                        // Hack for windows who tends to use `\` as separator instead of `/`
+                        .replace('\\', "/");
+
+                    // Add link
+                    out.write(&utils::fs::path_to_root(&current_path))?;
+                    out.write(&tmp)?;
+                    out.write("\"")?;
+
+                    if path == &current_path || is_first_chapter {
+                        is_first_chapter = false;
+                        out.write(" class=\"active\"")?;
+                    }
 
-                out.write(">")?;
-                true
-            } else {
-                out.write("<div>")?;
-                false
-            };
+                    out.write(">")?;
+                    path_exists = true;
+                }
+                _ => {
+                    out.write("<div>")?;
+                    path_exists = false;
+                }
+            }
 
             if !self.no_section_label {
                 // Section does not necessarily exist