Merge pull request #1389 from avitex/search-chapter-name

Add chapter name to search result breadcrumbs
This commit is contained in:
Eric Huss 2021-01-04 14:01:30 -08:00 committed by GitHub
commit 33d3d9c3ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 74 deletions

View File

@ -95,6 +95,8 @@ fn render_item(
let mut breadcrumbs = chapter.parent_names.clone(); let mut breadcrumbs = chapter.parent_names.clone();
let mut footnote_numbers = HashMap::new(); let mut footnote_numbers = HashMap::new();
breadcrumbs.push(chapter.name.clone());
while let Some(event) = p.next() { while let Some(event) = p.next() {
match event { match event {
Event::Start(Tag::Heading(i)) if i <= max_section_depth => { Event::Start(Tag::Heading(i)) if i <= max_section_depth => {

View File

@ -595,7 +595,10 @@ mod search {
docs[&summary]["body"], docs[&summary]["body"],
"Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion" "Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion"
); );
assert_eq!(docs[&summary]["breadcrumbs"], "First Chapter » Summary"); assert_eq!(
docs[&summary]["breadcrumbs"],
"First Chapter » Includes » Summary"
);
assert_eq!(docs[&conclusion]["body"], "I put &lt;HTML&gt; in here!"); assert_eq!(docs[&conclusion]["body"], "I put &lt;HTML&gt; in here!");
} }

View File

@ -27,234 +27,234 @@
"docInfo": { "docInfo": {
"0": { "0": {
"body": 9, "body": 9,
"breadcrumbs": 2, "breadcrumbs": 4,
"title": 2 "title": 2
}, },
"1": { "1": {
"body": 3, "body": 3,
"breadcrumbs": 1, "breadcrumbs": 2,
"title": 1 "title": 1
}, },
"10": { "10": {
"body": 16, "body": 16,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
}, },
"11": { "11": {
"body": 3, "body": 3,
"breadcrumbs": 4, "breadcrumbs": 5,
"title": 2 "title": 2
}, },
"12": { "12": {
"body": 4, "body": 4,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
}, },
"13": { "13": {
"body": 12, "body": 12,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
}, },
"14": { "14": {
"body": 2, "body": 2,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
}, },
"15": { "15": {
"body": 3, "body": 3,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
}, },
"16": { "16": {
"body": 29, "body": 29,
"breadcrumbs": 5, "breadcrumbs": 6,
"title": 3 "title": 3
}, },
"17": { "17": {
"body": 20, "body": 20,
"breadcrumbs": 2, "breadcrumbs": 4,
"title": 2 "title": 2
}, },
"18": { "18": {
"body": 18, "body": 18,
"breadcrumbs": 7, "breadcrumbs": 9,
"title": 5 "title": 5
}, },
"19": { "19": {
"body": 0, "body": 0,
"breadcrumbs": 3, "breadcrumbs": 5,
"title": 1 "title": 1
}, },
"2": { "2": {
"body": 2, "body": 2,
"breadcrumbs": 2, "breadcrumbs": 4,
"title": 2 "title": 2
}, },
"20": { "20": {
"body": 3, "body": 3,
"breadcrumbs": 1, "breadcrumbs": 2,
"title": 1 "title": 1
}, },
"3": { "3": {
"body": 0, "body": 0,
"breadcrumbs": 1, "breadcrumbs": 3,
"title": 1 "title": 1
}, },
"4": { "4": {
"body": 4, "body": 4,
"breadcrumbs": 4, "breadcrumbs": 6,
"title": 2 "title": 2
}, },
"5": { "5": {
"body": 1, "body": 1,
"breadcrumbs": 3, "breadcrumbs": 5,
"title": 1 "title": 1
}, },
"6": { "6": {
"body": 21, "body": 21,
"breadcrumbs": 9, "breadcrumbs": 11,
"title": 7 "title": 7
}, },
"7": { "7": {
"body": 6, "body": 6,
"breadcrumbs": 8, "breadcrumbs": 10,
"title": 6 "title": 6
}, },
"8": { "8": {
"body": 6, "body": 6,
"breadcrumbs": 6, "breadcrumbs": 8,
"title": 4 "title": 4
}, },
"9": { "9": {
"body": 0, "body": 0,
"breadcrumbs": 3, "breadcrumbs": 4,
"title": 1 "title": 1
} }
}, },
"docs": { "docs": {
"0": { "0": {
"body": "This file is just here to cause the index preprocessor to run. Does a pretty good job, too.", "body": "This file is just here to cause the index preprocessor to run. Does a pretty good job, too.",
"breadcrumbs": "Dummy Book", "breadcrumbs": "Dummy Book » Dummy Book",
"id": "0", "id": "0",
"title": "Dummy Book" "title": "Dummy Book"
}, },
"1": { "1": {
"body": "Here's some interesting text...", "body": "Here's some interesting text...",
"breadcrumbs": "Introduction", "breadcrumbs": "Introduction » Introduction",
"id": "1", "id": "1",
"title": "Introduction" "title": "Introduction"
}, },
"10": { "10": {
"body": "Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion", "body": "Dummy Book Introduction First Chapter Nested Chapter Includes Recursive Markdown Unicode Second Chapter Nested Chapter Conclusion",
"breadcrumbs": "First Chapter » Summary", "breadcrumbs": "First Chapter » Includes » Summary",
"id": "10", "id": "10",
"title": "Summary" "title": "Summary"
}, },
"11": { "11": {
"body": "Tests for some markdown output.", "body": "Tests for some markdown output.",
"breadcrumbs": "First Chapter » Markdown tests", "breadcrumbs": "First Chapter » Markdown » Markdown tests",
"id": "11", "id": "11",
"title": "Markdown tests" "title": "Markdown tests"
}, },
"12": { "12": {
"body": "foo bar baz bim", "body": "foo bar baz bim",
"breadcrumbs": "First Chapter » Tables", "breadcrumbs": "First Chapter » Markdown » Tables",
"id": "12", "id": "12",
"title": "Tables" "title": "Tables"
}, },
"13": { "13": {
"body": "Footnote example [1] , or with a word [2] . This is a footnote. A longer footnote. With multiple lines. Third line.", "body": "Footnote example [1] , or with a word [2] . This is a footnote. A longer footnote. With multiple lines. Third line.",
"breadcrumbs": "First Chapter » Footnotes", "breadcrumbs": "First Chapter » Markdown » Footnotes",
"id": "13", "id": "13",
"title": "Footnotes" "title": "Footnotes"
}, },
"14": { "14": {
"body": "strikethrough example", "body": "strikethrough example",
"breadcrumbs": "First Chapter » Strikethrough", "breadcrumbs": "First Chapter » Markdown » Strikethrough",
"id": "14", "id": "14",
"title": "Strikethrough" "title": "Strikethrough"
}, },
"15": { "15": {
"body": "Apples Broccoli Carrots", "body": "Apples Broccoli Carrots",
"breadcrumbs": "First Chapter » Tasklisks", "breadcrumbs": "First Chapter » Markdown » Tasklisks",
"id": "15", "id": "15",
"title": "Tasklisks" "title": "Tasklisks"
}, },
"16": { "16": {
"body": "Please be careful editing, this contains carefully crafted characters. Two byte character: spatiëring Combining character: spatiëring Three byte character: 书こんにちは Four byte character: 𐌀‮𐌁‮𐌂‮𐌃‮𐌄‮𐌅‮𐌆‮𐌇‮𐌈‬ Right-to-left: مرحبا Emoticons: 🔊 😍 💜 1⃣ right-to-left mark: hello באמת! Zalgo: ǫ̛̖̱̗̝͈̋͒͋̏ͥͫ̒̆ͩ̏͌̾͊͐ͪ̾̚", "body": "Please be careful editing, this contains carefully crafted characters. Two byte character: spatiëring Combining character: spatiëring Three byte character: 书こんにちは Four byte character: 𐌀‮𐌁‮𐌂‮𐌃‮𐌄‮𐌅‮𐌆‮𐌇‮𐌈‬ Right-to-left: مرحبا Emoticons: 🔊 😍 💜 1⃣ right-to-left mark: hello באמת! Zalgo: ǫ̛̖̱̗̝͈̋͒͋̏ͥͫ̒̆ͩ̏͌̾͊͐ͪ̾̚",
"breadcrumbs": "First Chapter » Unicode stress tests", "breadcrumbs": "First Chapter » Unicode » Unicode stress tests",
"id": "16", "id": "16",
"title": "Unicode stress tests" "title": "Unicode stress tests"
}, },
"17": { "17": {
"body": "This makes sure you can insert runnable Rust files. fn main() { println!(\"Hello World!\");\n#\n# // You can even hide lines! :D\n# println!(\"I am hidden! Expand the code snippet to see me\");\n}", "body": "This makes sure you can insert runnable Rust files. fn main() { println!(\"Hello World!\");\n#\n# // You can even hide lines! :D\n# println!(\"I am hidden! Expand the code snippet to see me\");\n}",
"breadcrumbs": "Second Chapter", "breadcrumbs": "Second Chapter » Second Chapter",
"id": "17", "id": "17",
"title": "Second Chapter" "title": "Second Chapter"
}, },
"18": { "18": {
"body": "When we link to the first section , it should work on both the print page and the non-print page. A fragment link should work. Link outside . Some image HTML Link", "body": "When we link to the first section , it should work on both the print page and the non-print page. A fragment link should work. Link outside . Some image HTML Link",
"breadcrumbs": "Second Chapter » Testing relative links for the print page", "breadcrumbs": "Second Chapter » Nested Chapter » Testing relative links for the print page",
"id": "18", "id": "18",
"title": "Testing relative links for the print page" "title": "Testing relative links for the print page"
}, },
"19": { "19": {
"body": "", "body": "",
"breadcrumbs": "Second Chapter » Some section", "breadcrumbs": "Second Chapter » Nested Chapter » Some section",
"id": "19", "id": "19",
"title": "Some section" "title": "Some section"
}, },
"2": { "2": {
"body": "more text.", "body": "more text.",
"breadcrumbs": "First Chapter", "breadcrumbs": "First Chapter » First Chapter",
"id": "2", "id": "2",
"title": "First Chapter" "title": "First Chapter"
}, },
"20": { "20": {
"body": "I put &lt;HTML&gt; in here!", "body": "I put &lt;HTML&gt; in here!",
"breadcrumbs": "Conclusion", "breadcrumbs": "Conclusion » Conclusion",
"id": "20", "id": "20",
"title": "Conclusion" "title": "Conclusion"
}, },
"3": { "3": {
"body": "", "body": "",
"breadcrumbs": "Some Section", "breadcrumbs": "First Chapter » Some Section",
"id": "3", "id": "3",
"title": "Some Section" "title": "Some Section"
}, },
"4": { "4": {
"body": "This file has some testable code. assert!(true);", "body": "This file has some testable code. assert!(true);",
"breadcrumbs": "First Chapter » Nested Chapter", "breadcrumbs": "First Chapter » Nested Chapter » Nested Chapter",
"id": "4", "id": "4",
"title": "Nested Chapter" "title": "Nested Chapter"
}, },
"5": { "5": {
"body": "assert!(true);", "body": "assert!(true);",
"breadcrumbs": "First Chapter » Some Section", "breadcrumbs": "First Chapter » Nested Chapter » Some Section",
"id": "5", "id": "5",
"title": "Some Section" "title": "Some Section"
}, },
"6": { "6": {
"body": "// The next line will cause a `rendered_output` test to fail if the anchor feature is broken in\n// such a way that the content between anchors isn't included.\n// unique-string-for-anchor-test\nassert!(true);", "body": "// The next line will cause a `rendered_output` test to fail if the anchor feature is broken in\n// such a way that the content between anchors isn't included.\n// unique-string-for-anchor-test\nassert!(true);",
"breadcrumbs": "First Chapter » Anchors include the part of a file between special comments", "breadcrumbs": "First Chapter » Nested Chapter » Anchors include the part of a file between special comments",
"id": "6", "id": "6",
"title": "Anchors include the part of a file between special comments" "title": "Anchors include the part of a file between special comments"
}, },
"7": { "7": {
"body": "# fn some_function() {\n# assert!(true);\n# }\n# fn main() { some_function();\n}", "body": "# fn some_function() {\n# assert!(true);\n# }\n# fn main() { some_function();\n}",
"breadcrumbs": "First Chapter » Rustdoc include adds the rest of the file as hidden", "breadcrumbs": "First Chapter » Nested Chapter » Rustdoc include adds the rest of the file as hidden",
"id": "7", "id": "7",
"title": "Rustdoc include adds the rest of the file as hidden" "title": "Rustdoc include adds the rest of the file as hidden"
}, },
"8": { "8": {
"body": "# fn some_other_function() {\n# assert!(true);\n# }\n# fn main() { some_other_function();\n}", "body": "# fn some_other_function() {\n# assert!(true);\n# }\n# fn main() { some_other_function();\n}",
"breadcrumbs": "First Chapter » Rustdoc include works with anchors too", "breadcrumbs": "First Chapter » Nested Chapter » Rustdoc include works with anchors too",
"id": "8", "id": "8",
"title": "Rustdoc include works with anchors too" "title": "Rustdoc include works with anchors too"
}, },
"9": { "9": {
"body": "", "body": "",
"breadcrumbs": "First Chapter » Includes", "breadcrumbs": "First Chapter » Includes » Includes",
"id": "9", "id": "9",
"title": "Includes" "title": "Includes"
} }
@ -3048,7 +3048,7 @@
"df": 2, "df": 2,
"docs": { "docs": {
"0": { "0": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
}, },
"10": { "10": {
"tf": 1.0 "tf": 1.0
@ -3222,7 +3222,7 @@
"df": 0, "df": 0,
"docs": {}, "docs": {},
"r": { "r": {
"df": 17, "df": 18,
"docs": { "docs": {
"10": { "10": {
"tf": 2.23606797749979 "tf": 2.23606797749979
@ -3246,31 +3246,34 @@
"tf": 1.0 "tf": 1.0
}, },
"17": { "17": {
"tf": 1.4142135623730951
},
"18": {
"tf": 1.0
},
"19": {
"tf": 1.0
},
"2": {
"tf": 1.4142135623730951
},
"4": {
"tf": 1.7320508075688772 "tf": 1.7320508075688772
}, },
"5": { "18": {
"tf": 1.4142135623730951
},
"19": {
"tf": 1.4142135623730951
},
"2": {
"tf": 1.7320508075688772
},
"3": {
"tf": 1.0 "tf": 1.0
}, },
"4": {
"tf": 2.0
},
"5": {
"tf": 1.4142135623730951
},
"6": { "6": {
"tf": 1.0 "tf": 1.4142135623730951
}, },
"7": { "7": {
"tf": 1.0 "tf": 1.4142135623730951
}, },
"8": { "8": {
"tf": 1.0 "tf": 1.4142135623730951
}, },
"9": { "9": {
"tf": 1.0 "tf": 1.0
@ -3379,7 +3382,7 @@
"tf": 1.0 "tf": 1.0
}, },
"20": { "20": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
} }
} }
} }
@ -3467,7 +3470,7 @@
"df": 2, "df": 2,
"docs": { "docs": {
"0": { "0": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
}, },
"10": { "10": {
"tf": 1.0 "tf": 1.0
@ -3672,7 +3675,7 @@
"df": 0, "df": 0,
"docs": {}, "docs": {},
"t": { "t": {
"df": 15, "df": 16,
"docs": { "docs": {
"10": { "10": {
"tf": 1.4142135623730951 "tf": 1.4142135623730951
@ -3699,7 +3702,10 @@
"tf": 1.0 "tf": 1.0
}, },
"2": { "2": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
},
"3": {
"tf": 1.0
}, },
"4": { "4": {
"tf": 1.0 "tf": 1.0
@ -3964,7 +3970,7 @@
"df": 5, "df": 5,
"docs": { "docs": {
"10": { "10": {
"tf": 1.0 "tf": 1.4142135623730951
}, },
"6": { "6": {
"tf": 1.7320508075688772 "tf": 1.7320508075688772
@ -3976,7 +3982,7 @@
"tf": 1.4142135623730951 "tf": 1.4142135623730951
}, },
"9": { "9": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
} }
} }
}, },
@ -4065,7 +4071,7 @@
"df": 2, "df": 2,
"docs": { "docs": {
"1": { "1": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
}, },
"10": { "10": {
"tf": 1.0 "tf": 1.0
@ -4282,13 +4288,25 @@
"df": 0, "df": 0,
"docs": {}, "docs": {},
"n": { "n": {
"df": 2, "df": 6,
"docs": { "docs": {
"10": { "10": {
"tf": 1.0 "tf": 1.0
}, },
"11": { "11": {
"tf": 1.7320508075688772 "tf": 2.0
},
"12": {
"tf": 1.0
},
"13": {
"tf": 1.0
},
"14": {
"tf": 1.0
},
"15": {
"tf": 1.0
} }
} }
} }
@ -4361,13 +4379,31 @@
"df": 0, "df": 0,
"docs": {}, "docs": {},
"t": { "t": {
"df": 2, "df": 8,
"docs": { "docs": {
"10": { "10": {
"tf": 1.4142135623730951 "tf": 1.4142135623730951
}, },
"18": {
"tf": 1.0
},
"19": {
"tf": 1.0
},
"4": { "4": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
},
"5": {
"tf": 1.0
},
"6": {
"tf": 1.0
},
"7": {
"tf": 1.0
},
"8": {
"tf": 1.0
} }
} }
} }
@ -4843,7 +4879,7 @@
"tf": 1.0 "tf": 1.0
}, },
"17": { "17": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
}, },
"18": { "18": {
"tf": 1.0 "tf": 1.0
@ -5385,7 +5421,7 @@
"tf": 1.0 "tf": 1.0
}, },
"16": { "16": {
"tf": 1.4142135623730951 "tf": 1.7320508075688772
} }
} }
}, },