@@ -25,7 +25,9 @@ use crate::helpers::title::{TitleFormat, page_title, render_title, transform_tit
2525use crate :: html:: banner:: build_banner;
2626use crate :: html:: bubble_up:: bubble_up_curriculum_page;
2727use crate :: html:: code:: { Code , code_blocks} ;
28- use crate :: html:: modifier:: { add_missing_ids, insert_self_links_for_dts, remove_empty_p} ;
28+ use crate :: html:: modifier:: {
29+ add_missing_ids, collect_fragment_ids, insert_self_links_for_dts, remove_empty_p,
30+ } ;
2931use crate :: html:: rewriter:: { post_process_html, post_process_inline_sidebar} ;
3032use crate :: html:: sections:: { BuildSection , BuildSectionType , Split , split_sections} ;
3133use crate :: html:: sidebar:: {
@@ -141,6 +143,7 @@ impl BuildSection<'_> {
141143pub struct PageContent {
142144 body : Vec < Section > ,
143145 toc : Vec < TocEntry > ,
146+ fragments : Vec < String > ,
144147 summary : Option < String > ,
145148 sidebar : Option < String > ,
146149 live_samples : Option < Vec < Code > > ,
@@ -208,10 +211,12 @@ fn build_content<T: PageLike>(page: &T) -> Result<PageContent, DocError> {
208211 Some ( sidebars. into_iter ( ) . collect :: < Result < String , _ > > ( ) ?)
209212 } ;
210213 let toc = make_toc ( & sections, matches ! ( page. page_type( ) , PageType :: Curriculum ) ) ;
214+ let fragments = collect_fragment_ids ( & fragment) ;
211215 let body = sections. into_iter ( ) . map ( Into :: into) . collect ( ) ;
212216 Ok ( PageContent {
213217 body,
214218 toc,
219+ fragments,
215220 summary,
216221 sidebar,
217222 live_samples,
@@ -231,6 +236,7 @@ fn build_doc(doc: &Doc) -> Result<BuiltPage, DocError> {
231236 let PageContent {
232237 body,
233238 toc,
239+ fragments,
234240 summary,
235241 sidebar,
236242 live_samples,
@@ -312,6 +318,7 @@ fn build_doc(doc: &Doc) -> Result<BuiltPage, DocError> {
312318 body,
313319 sidebar_html,
314320 toc,
321+ fragments,
315322 baseline,
316323 modified,
317324 summary,
@@ -344,6 +351,7 @@ fn build_blog_post(post: &BlogPost) -> Result<BuiltPage, DocError> {
344351 let PageContent {
345352 body,
346353 toc,
354+ fragments,
347355 live_samples,
348356 ..
349357 } = build_content ( post) ?;
@@ -356,6 +364,7 @@ fn build_blog_post(post: &BlogPost) -> Result<BuiltPage, DocError> {
356364 locale : post. locale ( ) ,
357365 body,
358366 toc,
367+ fragments,
359368 summary : Some ( post. meta . description . clone ( ) ) ,
360369 live_samples,
361370 ..Default :: default ( )
@@ -386,12 +395,18 @@ fn build_blog_post(post: &BlogPost) -> Result<BuiltPage, DocError> {
386395
387396fn build_generic_page ( page : & Generic ) -> Result < BuiltPage , DocError > {
388397 let built = build_content ( page) ;
389- let PageContent { body, toc, .. } = built?;
398+ let PageContent {
399+ body,
400+ toc,
401+ fragments,
402+ ..
403+ } = built?;
390404 Ok ( BuiltPage :: GenericPage ( Box :: new ( JsonGenericPage {
391405 hy_data : JsonGenericHyData {
392406 sections : body,
393407 title : page. meta . title . clone ( ) ,
394408 toc,
409+ fragments,
395410 } ,
396411 short_title : page. meta . short_title . clone ( ) ,
397412 page_title : if let Some ( suffix) = & page. meta . title_suffix {
@@ -419,7 +434,12 @@ fn build_spa(spa: &SPA) -> Result<BuiltPage, DocError> {
419434}
420435
421436fn build_curriculum ( curriculum : & Curriculum ) -> Result < BuiltPage , DocError > {
422- let PageContent { body, toc, .. } = build_content ( curriculum) ?;
437+ let PageContent {
438+ body,
439+ toc,
440+ fragments,
441+ ..
442+ } = build_content ( curriculum) ?;
423443 let sidebar = build_sidebar ( ) . ok ( ) ;
424444 let group = curriculum_group ( & parents ( curriculum) ) ;
425445 let modules = match curriculum. meta . template {
@@ -444,6 +464,7 @@ fn build_curriculum(curriculum: &Curriculum) -> Result<BuiltPage, DocError> {
444464 body,
445465 sidebar,
446466 toc,
467+ fragments,
447468 group,
448469 modules,
449470 prev_next,
0 commit comments