@@ -19,7 +19,11 @@ lazy_static! {
19
19
regex:: Regex :: new( r"^\[(\S+)\](?:\.(\S+)|\s|)$" ) . unwrap( ) ;
20
20
}
21
21
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 > {
23
27
JSDOC_LINK_RE . replace_all ( md, |captures : & regex:: Captures | {
24
28
let code = captures
25
29
. name ( "modifier" )
@@ -111,7 +115,9 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
111
115
( title, link)
112
116
} ;
113
117
114
- if LINK_RE . is_match ( & link) {
118
+ if strip {
119
+ title
120
+ } else if LINK_RE . is_match ( & link) {
115
121
if code {
116
122
format ! ( "[`{title}`]({link})" )
117
123
} else {
@@ -122,7 +128,7 @@ fn parse_links<'a>(md: &'a str, ctx: &RenderContext) -> Cow<'a, str> {
122
128
if code {
123
129
format ! ( "`{title}`" )
124
130
} else {
125
- title. to_string ( )
131
+ title
126
132
}
127
133
}
128
134
} )
@@ -149,7 +155,7 @@ pub struct MarkdownToHTMLOptions {
149
155
pub type MarkdownStripper = std:: rc:: Rc < dyn ( Fn ( & str ) -> String ) > ;
150
156
151
157
pub 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 ) ;
153
159
154
160
( render_ctx. ctx . markdown_stripper ) ( & md)
155
161
}
@@ -200,7 +206,7 @@ pub fn markdown_to_html(
200
206
anchorizer. as_ref ( ) ,
201
207
) ;
202
208
203
- let md = parse_links ( md, render_ctx) ;
209
+ let md = parse_links ( md, render_ctx, false ) ;
204
210
205
211
let file = render_ctx. get_current_resolve ( ) . get_file ( ) . cloned ( ) ;
206
212
@@ -281,7 +287,7 @@ pub(crate) fn jsdoc_examples(
281
287
#[ derive( Debug , Serialize , Clone ) ]
282
288
pub struct ExampleCtx {
283
289
pub anchor : AnchorCtx ,
284
- pub id : String ,
290
+ pub id : Id ,
285
291
pub title : String ,
286
292
pub markdown_title : String ,
287
293
markdown_body : String ,
@@ -291,7 +297,11 @@ impl ExampleCtx {
291
297
pub const TEMPLATE : & ' static str = "example" ;
292
298
293
299
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 ( ) ;
295
305
296
306
let ( maybe_title, body) = split_markdown_title ( example) ;
297
307
let title = if let Some ( title) = maybe_title {
@@ -305,8 +315,8 @@ impl ExampleCtx {
305
315
render_markdown ( render_ctx, body. unwrap_or_default ( ) , true ) ;
306
316
307
317
ExampleCtx {
308
- anchor : AnchorCtx { id : id. to_string ( ) } ,
309
- id : id . to_string ( ) ,
318
+ anchor : AnchorCtx { id : id. clone ( ) } ,
319
+ id,
310
320
title,
311
321
markdown_title,
312
322
markdown_body,
@@ -368,7 +378,9 @@ impl ModuleDocCtx {
368
378
render_ctx. clone ( ) ,
369
379
Some ( SectionHeaderCtx {
370
380
title : title. clone ( ) ,
371
- anchor : AnchorCtx { id : title } ,
381
+ anchor : AnchorCtx {
382
+ id : super :: util:: Id :: new ( title) ,
383
+ } ,
372
384
href : None ,
373
385
doc : None ,
374
386
} ) ,
@@ -381,7 +393,7 @@ impl ModuleDocCtx {
381
393
Self {
382
394
deprecated,
383
395
sections : super :: SymbolContentCtx {
384
- id : "module_doc" . to_string ( ) ,
396
+ id : Id :: new ( "module_doc" ) ,
385
397
docs : html,
386
398
sections,
387
399
} ,
@@ -490,6 +502,7 @@ mod test {
490
502
) ,
491
503
markdown_stripper : Rc :: new ( crate :: html:: comrak:: strip) ,
492
504
head_inject : None ,
505
+ id_prefix : None ,
493
506
} ,
494
507
Default :: default ( ) ,
495
508
Default :: default ( ) ,
@@ -569,65 +582,78 @@ mod test {
569
582
) ;
570
583
571
584
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 ) ,
573
586
"foo [https://example.com](https://example.com) bar"
574
587
) ;
575
588
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
+ ) ,
577
594
"foo [`https://example.com`](https://example.com) bar"
578
595
) ;
579
596
580
597
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
+ ) ,
582
603
"foo [Example](https://example.com) bar"
583
604
) ;
584
605
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
+ ) ,
586
611
"foo [Example](https://example.com) bar"
587
612
) ;
588
613
assert_eq ! (
589
614
parse_links(
590
615
"foo {@linkcode https://example.com Example} bar" ,
591
- & render_ctx
616
+ & render_ctx,
617
+ false ,
592
618
) ,
593
619
"foo [`Example`](https://example.com) bar"
594
620
) ;
595
621
596
622
assert_eq ! (
597
- parse_links( "foo {@link unknownSymbol} bar" , & render_ctx) ,
623
+ parse_links( "foo {@link unknownSymbol} bar" , & render_ctx, false ) ,
598
624
"foo unknownSymbol bar"
599
625
) ;
600
626
assert_eq ! (
601
- parse_links( "foo {@linkcode unknownSymbol} bar" , & render_ctx) ,
627
+ parse_links( "foo {@linkcode unknownSymbol} bar" , & render_ctx, false ) ,
602
628
"foo `unknownSymbol` bar"
603
629
) ;
604
630
605
631
#[ cfg( not( target_os = "windows" ) ) ]
606
632
{
607
633
assert_eq ! (
608
- parse_links( "foo {@link bar} bar" , & render_ctx) ,
634
+ parse_links( "foo {@link bar} bar" , & render_ctx, false ) ,
609
635
"foo [bar](../../.././/a.ts/~/bar.html) bar"
610
636
) ;
611
637
assert_eq ! (
612
- parse_links( "foo {@linkcode bar} bar" , & render_ctx) ,
638
+ parse_links( "foo {@linkcode bar} bar" , & render_ctx, false ) ,
613
639
"foo [`bar`](../../.././/a.ts/~/bar.html) bar"
614
640
) ;
615
641
616
642
assert_eq ! (
617
- parse_links( "foo {@link [b.ts]} bar" , & render_ctx) ,
643
+ parse_links( "foo {@link [b.ts]} bar" , & render_ctx, false ) ,
618
644
"foo [b.ts](../../.././/b.ts/index.html) bar"
619
645
) ;
620
646
assert_eq ! (
621
- parse_links( "foo {@linkcode [b.ts]} bar" , & render_ctx) ,
647
+ parse_links( "foo {@linkcode [b.ts]} bar" , & render_ctx, false ) ,
622
648
"foo [`b.ts`](../../.././/b.ts/index.html) bar"
623
649
) ;
624
650
625
651
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 ) ,
627
653
"foo [b.ts baz](../../.././/b.ts/~/baz.html) bar"
628
654
) ;
629
655
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 ) ,
631
657
"foo [`b.ts baz`](../../.././/b.ts/~/baz.html) bar"
632
658
) ;
633
659
}
0 commit comments