1
1
use super :: render_context:: RenderContext ;
2
2
use super :: util:: * ;
3
- use crate :: html:: usage:: UsagesCtx ;
4
3
use crate :: html:: ShortPath ;
5
4
use crate :: js_doc:: JsDoc ;
6
5
use crate :: js_doc:: JsDocTag ;
@@ -13,7 +12,6 @@ use comrak::Arena;
13
12
use serde:: Serialize ;
14
13
use std:: borrow:: Cow ;
15
14
use std:: cell:: RefCell ;
16
- use std:: cmp:: Ordering ;
17
15
18
16
#[ cfg( feature = "ammonia" ) ]
19
17
use crate :: html:: comrak_adapters:: URLRewriter ;
@@ -247,23 +245,16 @@ fn render_node<'a>(
247
245
String :: from_utf8 ( bw. into_inner ( ) . unwrap ( ) ) . unwrap ( )
248
246
}
249
247
250
- #[ derive( Debug , Serialize , Clone , Default ) ]
251
- pub struct Markdown {
252
- pub html : String ,
253
- pub toc : Option < String > ,
254
- }
255
-
256
248
pub struct MarkdownToHTMLOptions {
257
249
pub summary : bool ,
258
250
pub summary_prefer_title : bool ,
259
- pub render_toc : bool ,
260
251
}
261
252
262
253
pub fn markdown_to_html (
263
254
render_ctx : & RenderContext ,
264
255
md : & str ,
265
256
render_options : MarkdownToHTMLOptions ,
266
- ) -> Option < Markdown > {
257
+ ) -> Option < String > {
267
258
// TODO(bartlomieju): this should be initialized only once
268
259
let mut options = comrak:: Options :: default ( ) ;
269
260
options. extension . autolink = true ;
@@ -285,9 +276,7 @@ pub fn markdown_to_html(
285
276
let mut plugins = comrak:: Plugins :: default ( ) ;
286
277
plugins. render . codefence_syntax_highlighter =
287
278
Some ( & render_ctx. ctx . highlight_adapter ) ;
288
- let heading_adapter =
289
- crate :: html:: comrak_adapters:: HeadingToCAdapter :: default ( ) ;
290
- plugins. render . heading_adapter = Some ( & heading_adapter) ;
279
+ plugins. render . heading_adapter = Some ( & render_ctx. toc ) ;
291
280
292
281
let md = parse_links ( md, render_ctx) ;
293
282
@@ -323,7 +312,7 @@ pub fn markdown_to_html(
323
312
let mut ammonia_builder = ammonia:: Builder :: default ( ) ;
324
313
325
314
ammonia_builder
326
- . add_tags ( [ "video" , "button" , "svg" , "path" ] )
315
+ . add_tags ( [ "video" , "button" , "svg" , "path" , "rect" ] )
327
316
. add_generic_attributes ( [ "id" , "align" ] )
328
317
. add_tag_attributes ( "button" , [ "data-copy" ] )
329
318
. add_tag_attributes (
@@ -353,6 +342,7 @@ pub fn markdown_to_html(
353
342
"stroke-linejoin" ,
354
343
] ,
355
344
)
345
+ . add_tag_attributes ( "rect" , [ "x" , "y" , "width" , "height" , "fill" ] )
356
346
. add_tag_attributes ( "video" , [ "src" , "controls" ] )
357
347
. add_allowed_classes ( "pre" , [ "highlight" ] )
358
348
. add_allowed_classes ( "button" , [ "context_button" ] )
@@ -387,46 +377,7 @@ pub fn markdown_to_html(
387
377
html = ammonia_builder. clean ( & html) . to_string ( ) ;
388
378
}
389
379
390
- let toc = if render_options. render_toc {
391
- let toc = heading_adapter. into_toc ( ) ;
392
-
393
- if toc. is_empty ( ) {
394
- None
395
- } else {
396
- let mut toc_content = vec ! [ String :: from( r#"<nav class="toc"><ul>"# ) ] ;
397
-
398
- let mut current_level = 1 ;
399
-
400
- for ( level, heading, anchor) in toc {
401
- match current_level. cmp ( & level) {
402
- Ordering :: Equal => { }
403
- Ordering :: Less => {
404
- toc_content. push ( r#"<li><ul>"# . to_string ( ) ) ;
405
- current_level = level;
406
- }
407
- Ordering :: Greater => {
408
- toc_content. push ( "</ul></li>" . to_string ( ) ) ;
409
- current_level = level;
410
- }
411
- }
412
-
413
- toc_content. push ( format ! (
414
- r##"<li><a href="#{anchor}" title="{heading}">{heading}</a></li>"##
415
- ) ) ;
416
- }
417
-
418
- toc_content. push ( String :: from ( "</ul></nav>" ) ) ;
419
-
420
- Some ( toc_content. join ( "" ) )
421
- }
422
- } else {
423
- None
424
- } ;
425
-
426
- Some ( Markdown {
427
- html : format ! ( r#"<div class="{class_name} flex-1">{html}</div>"# ) ,
428
- toc,
429
- } )
380
+ Some ( format ! ( r#"<div class="{class_name}">{html}</div>"# ) )
430
381
}
431
382
432
383
pub ( crate ) fn render_markdown_summary (
@@ -439,11 +390,9 @@ pub(crate) fn render_markdown_summary(
439
390
MarkdownToHTMLOptions {
440
391
summary : true ,
441
392
summary_prefer_title : false ,
442
- render_toc : false ,
443
393
} ,
444
394
)
445
395
. unwrap_or_default ( )
446
- . html
447
396
}
448
397
449
398
pub ( crate ) fn render_markdown ( render_ctx : & RenderContext , md : & str ) -> String {
@@ -453,11 +402,9 @@ pub(crate) fn render_markdown(render_ctx: &RenderContext, md: &str) -> String {
453
402
MarkdownToHTMLOptions {
454
403
summary : false ,
455
404
summary_prefer_title : false ,
456
- render_toc : false ,
457
405
} ,
458
406
)
459
407
. unwrap_or_default ( )
460
- . html
461
408
}
462
409
463
410
pub ( crate ) fn jsdoc_body_to_html (
@@ -472,10 +419,8 @@ pub(crate) fn jsdoc_body_to_html(
472
419
MarkdownToHTMLOptions {
473
420
summary,
474
421
summary_prefer_title : false ,
475
- render_toc : false ,
476
422
} ,
477
423
)
478
- . map ( |markdown| markdown. html )
479
424
} else {
480
425
None
481
426
}
@@ -503,6 +448,7 @@ pub(crate) fn jsdoc_examples(
503
448
504
449
if !examples. is_empty ( ) {
505
450
Some ( SectionCtx :: new (
451
+ ctx,
506
452
"Examples" ,
507
453
SectionContentCtx :: Example ( examples) ,
508
454
) )
@@ -547,8 +493,6 @@ impl ExampleCtx {
547
493
#[ derive( Debug , Serialize , Clone , Default ) ]
548
494
pub struct ModuleDocCtx {
549
495
pub deprecated : Option < String > ,
550
- pub usages : Option < UsagesCtx > ,
551
- pub toc : Option < String > ,
552
496
pub sections : super :: SymbolContentCtx ,
553
497
}
554
498
@@ -560,7 +504,7 @@ impl ModuleDocCtx {
560
504
561
505
let mut sections = Vec :: with_capacity ( 7 ) ;
562
506
563
- let ( deprecated, html, toc ) = if let Some ( node) = module_doc_nodes
507
+ let ( deprecated, html) = if let Some ( node) = module_doc_nodes
564
508
. iter ( )
565
509
. find ( |n| n. kind == DocNodeKind :: ModuleDoc )
566
510
{
@@ -579,26 +523,11 @@ impl ModuleDocCtx {
579
523
sections. push ( examples) ;
580
524
}
581
525
582
- let ( html, toc) = if let Some ( markdown) =
583
- node. js_doc . doc . as_ref ( ) . and_then ( |doc| {
584
- markdown_to_html (
585
- render_ctx,
586
- doc,
587
- MarkdownToHTMLOptions {
588
- summary : false ,
589
- summary_prefer_title : false ,
590
- render_toc : true ,
591
- } ,
592
- )
593
- } ) {
594
- ( Some ( markdown. html ) , markdown. toc )
595
- } else {
596
- ( None , None )
597
- } ;
526
+ let html = jsdoc_body_to_html ( render_ctx, & node. js_doc , false ) ;
598
527
599
- ( deprecated, html, toc )
528
+ ( deprecated, html)
600
529
} else {
601
- ( None , None , None )
530
+ ( None , None )
602
531
} ;
603
532
604
533
if !short_path. is_main {
@@ -612,7 +541,8 @@ impl ModuleDocCtx {
612
541
. map ( |( title, nodes) | {
613
542
(
614
543
SectionHeaderCtx {
615
- title,
544
+ title : title. clone ( ) ,
545
+ anchor : AnchorCtx { id : title } ,
616
546
href : None ,
617
547
doc : None ,
618
548
} ,
@@ -625,8 +555,6 @@ impl ModuleDocCtx {
625
555
626
556
Self {
627
557
deprecated,
628
- usages : UsagesCtx :: new ( render_ctx, & [ ] ) ,
629
- toc,
630
558
sections : super :: SymbolContentCtx {
631
559
id : "module_doc" . to_string ( ) ,
632
560
docs : html,
0 commit comments