@@ -19,7 +19,11 @@ lazy_static! {
1919 regex:: Regex :: new( r"^\[(\S+)\](?:\.(\S+)|\s|)$" ) . unwrap( ) ;
2020}
2121
22- fn parse_links < ' a > ( md : & ' a str , ctx : & RenderContext ) -> Cow < ' a , str > {
22+ fn parse_links < ' a > (
23+ md : & ' a str ,
24+ ctx : & RenderContext ,
25+ strip : bool ,
26+ ) -> Cow < ' a , str > {
2327 JSDOC_LINK_RE . replace_all ( md, |captures : & regex:: Captures | {
2428 let code = captures
2529 . name ( "modifier" )
@@ -111,7 +115,9 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
111115 ( title, link)
112116 } ;
113117
114- if LINK_RE . is_match ( & link) {
118+ if strip {
119+ title
120+ } else if LINK_RE . is_match ( & link) {
115121 if code {
116122 format ! ( "[`{title}`]({link})" )
117123 } else {
@@ -122,7 +128,7 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
122128 if code {
123129 format ! ( "`{title}`" )
124130 } else {
125- title. to_string ( )
131+ title
126132 }
127133 }
128134 } )
@@ -149,7 +155,7 @@ pub struct MarkdownToHTMLOptions {
149155pub type MarkdownStripper = std:: rc:: Rc < dyn ( Fn ( & str ) -> String ) > ;
150156
151157pub fn strip ( render_ctx : & RenderContext , md : & str ) -> String {
152- let md = parse_links ( md, render_ctx) ;
158+ let md = parse_links ( md, render_ctx, true ) ;
153159
154160 ( render_ctx. ctx . markdown_stripper ) ( & md)
155161}
@@ -200,7 +206,7 @@ pub fn markdown_to_html(
200206 anchorizer. as_ref ( ) ,
201207 ) ;
202208
203- let md = parse_links ( md, render_ctx) ;
209+ let md = parse_links ( md, render_ctx, false ) ;
204210
205211 let file = render_ctx. get_current_resolve ( ) . get_file ( ) . cloned ( ) ;
206212
@@ -281,7 +287,7 @@ pub(crate) fn jsdoc_examples(
281287#[ derive( Debug , Serialize , Clone ) ]
282288pub struct ExampleCtx {
283289 pub anchor : AnchorCtx ,
284- pub id : String ,
290+ pub id : Id ,
285291 pub title : String ,
286292 pub markdown_title : String ,
287293 markdown_body : String ,
@@ -291,7 +297,11 @@ impl ExampleCtx {
291297 pub const TEMPLATE : & ' static str = "example" ;
292298
293299 pub fn new ( render_ctx : & RenderContext , example : & str , i : usize ) -> Self {
294- let id = name_to_id ( "example" , & i. to_string ( ) ) ;
300+ // Using the context-aware builder with the Example kind
301+ let id = IdBuilder :: new ( render_ctx. ctx )
302+ . kind ( IdKind :: Example )
303+ . index ( i)
304+ . build ( ) ;
295305
296306 let ( maybe_title, body) = split_markdown_title ( example) ;
297307 let title = if let Some ( title) = maybe_title {
@@ -305,8 +315,8 @@ impl ExampleCtx {
305315 render_markdown ( render_ctx, body. unwrap_or_default ( ) , true ) ;
306316
307317 ExampleCtx {
308- anchor : AnchorCtx { id : id. to_string ( ) } ,
309- id : id . to_string ( ) ,
318+ anchor : AnchorCtx { id : id. clone ( ) } ,
319+ id,
310320 title,
311321 markdown_title,
312322 markdown_body,
@@ -368,7 +378,9 @@ impl ModuleDocCtx {
368378 render_ctx. clone ( ) ,
369379 Some ( SectionHeaderCtx {
370380 title : title. clone ( ) ,
371- anchor : AnchorCtx { id : title } ,
381+ anchor : AnchorCtx {
382+ id : super :: util:: Id :: new ( title) ,
383+ } ,
372384 href : None ,
373385 doc : None ,
374386 } ) ,
@@ -381,7 +393,7 @@ impl ModuleDocCtx {
381393 Self {
382394 deprecated,
383395 sections : super :: SymbolContentCtx {
384- id : "module_doc" . to_string ( ) ,
396+ id : Id :: new ( "module_doc" ) ,
385397 docs : html,
386398 sections,
387399 } ,
@@ -490,6 +502,7 @@ mod test {
490502 ) ,
491503 markdown_stripper : Rc :: new ( crate :: html:: comrak:: strip) ,
492504 head_inject : None ,
505+ id_prefix : None ,
493506 } ,
494507 Default :: default ( ) ,
495508 Default :: default ( ) ,
@@ -569,65 +582,78 @@ mod test {
569582 ) ;
570583
571584 assert_eq ! (
572- parse_links( "foo {@link https://example.com} bar" , & render_ctx) ,
585+ parse_links( "foo {@link https://example.com} bar" , & render_ctx, false ) ,
573586 "foo [https://example.com](https://example.com) bar"
574587 ) ;
575588 assert_eq ! (
576- parse_links( "foo {@linkcode https://example.com} bar" , & render_ctx) ,
589+ parse_links(
590+ "foo {@linkcode https://example.com} bar" ,
591+ & render_ctx,
592+ false
593+ ) ,
577594 "foo [`https://example.com`](https://example.com) bar"
578595 ) ;
579596
580597 assert_eq ! (
581- parse_links( "foo {@link https://example.com Example} bar" , & render_ctx) ,
598+ parse_links(
599+ "foo {@link https://example.com Example} bar" ,
600+ & render_ctx,
601+ false
602+ ) ,
582603 "foo [Example](https://example.com) bar"
583604 ) ;
584605 assert_eq ! (
585- parse_links( "foo {@link https://example.com|Example} bar" , & render_ctx) ,
606+ parse_links(
607+ "foo {@link https://example.com|Example} bar" ,
608+ & render_ctx,
609+ false
610+ ) ,
586611 "foo [Example](https://example.com) bar"
587612 ) ;
588613 assert_eq ! (
589614 parse_links(
590615 "foo {@linkcode https://example.com Example} bar" ,
591- & render_ctx
616+ & render_ctx,
617+ false ,
592618 ) ,
593619 "foo [`Example`](https://example.com) bar"
594620 ) ;
595621
596622 assert_eq ! (
597- parse_links( "foo {@link unknownSymbol} bar" , & render_ctx) ,
623+ parse_links( "foo {@link unknownSymbol} bar" , & render_ctx, false ) ,
598624 "foo unknownSymbol bar"
599625 ) ;
600626 assert_eq ! (
601- parse_links( "foo {@linkcode unknownSymbol} bar" , & render_ctx) ,
627+ parse_links( "foo {@linkcode unknownSymbol} bar" , & render_ctx, false ) ,
602628 "foo `unknownSymbol` bar"
603629 ) ;
604630
605631 #[ cfg( not( target_os = "windows" ) ) ]
606632 {
607633 assert_eq ! (
608- parse_links( "foo {@link bar} bar" , & render_ctx) ,
634+ parse_links( "foo {@link bar} bar" , & render_ctx, false ) ,
609635 "foo [bar](../../.././/a.ts/~/bar.html) bar"
610636 ) ;
611637 assert_eq ! (
612- parse_links( "foo {@linkcode bar} bar" , & render_ctx) ,
638+ parse_links( "foo {@linkcode bar} bar" , & render_ctx, false ) ,
613639 "foo [`bar`](../../.././/a.ts/~/bar.html) bar"
614640 ) ;
615641
616642 assert_eq ! (
617- parse_links( "foo {@link [b.ts]} bar" , & render_ctx) ,
643+ parse_links( "foo {@link [b.ts]} bar" , & render_ctx, false ) ,
618644 "foo [b.ts](../../.././/b.ts/index.html) bar"
619645 ) ;
620646 assert_eq ! (
621- parse_links( "foo {@linkcode [b.ts]} bar" , & render_ctx) ,
647+ parse_links( "foo {@linkcode [b.ts]} bar" , & render_ctx, false ) ,
622648 "foo [`b.ts`](../../.././/b.ts/index.html) bar"
623649 ) ;
624650
625651 assert_eq ! (
626- parse_links( "foo {@link [b.ts].baz} bar" , & render_ctx) ,
652+ parse_links( "foo {@link [b.ts].baz} bar" , & render_ctx, false ) ,
627653 "foo [b.ts baz](../../.././/b.ts/~/baz.html) bar"
628654 ) ;
629655 assert_eq ! (
630- parse_links( "foo {@linkcode [b.ts].baz} bar" , & render_ctx) ,
656+ parse_links( "foo {@linkcode [b.ts].baz} bar" , & render_ctx, false ) ,
631657 "foo [`b.ts baz`](../../.././/b.ts/~/baz.html) bar"
632658 ) ;
633659 }
0 commit comments