@@ -124,6 +124,9 @@ pub struct SharedContext {
124
124
/// The given user css file which allow to customize the generated
125
125
/// documentation theme.
126
126
pub css_file_extension : Option < PathBuf > ,
127
+ /// Warnings for the user if rendering would differ using different markdown
128
+ /// parsers.
129
+ pub markdown_warnings : RefCell < Vec < ( String , Vec < String > ) > > ,
127
130
}
128
131
129
132
/// Indicates where an external crate can be found.
@@ -457,6 +460,7 @@ pub fn run(mut krate: clean::Crate,
457
460
krate : krate. name . clone ( ) ,
458
461
} ,
459
462
css_file_extension : css_file_extension. clone ( ) ,
463
+ markdown_warnings : RefCell :: new ( vec ! [ ] ) ,
460
464
} ;
461
465
462
466
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -579,8 +583,19 @@ pub fn run(mut krate: clean::Crate,
579
583
580
584
write_shared ( & cx, & krate, & * cache, index) ?;
581
585
586
+ let scx = cx. shared . clone ( ) ;
587
+
582
588
// And finally render the whole crate's documentation
583
- cx. krate ( krate)
589
+ let result = cx. krate ( krate) ;
590
+
591
+ let markdown_warnings = scx. markdown_warnings . borrow ( ) ;
592
+ for & ( ref text, ref diffs) in & * markdown_warnings {
593
+ println ! ( "Differences spotted in {:?}:\n {}" ,
594
+ text,
595
+ diffs. join( "\n " ) ) ;
596
+ }
597
+
598
+ result
584
599
}
585
600
586
601
/// Build the search index from the collected metadata
@@ -1641,12 +1656,18 @@ fn plain_summary_line(s: Option<&str>) -> String {
1641
1656
fn document ( w : & mut fmt:: Formatter , cx : & Context , item : & clean:: Item ) -> fmt:: Result {
1642
1657
document_stability ( w, cx, item) ?;
1643
1658
let prefix = render_assoc_const_value ( item) ;
1644
- document_full ( w, item, cx. render_type , & prefix) ?;
1659
+ document_full ( w, item, cx, & prefix) ?;
1645
1660
Ok ( ( ) )
1646
1661
}
1647
1662
1648
- fn render_markdown ( w : & mut fmt:: Formatter , md_text : & str , render_type : RenderType ,
1649
- prefix : & str ) -> fmt:: Result {
1663
+ /// Render md_text as markdown. Warns the user if there are difference in
1664
+ /// rendering between Pulldown and Hoedown.
1665
+ fn render_markdown ( w : & mut fmt:: Formatter ,
1666
+ md_text : & str ,
1667
+ render_type : RenderType ,
1668
+ prefix : & str ,
1669
+ scx : & SharedContext )
1670
+ -> fmt:: Result {
1650
1671
let hoedown_output = format ! ( "{}" , Markdown ( md_text, RenderType :: Hoedown ) ) ;
1651
1672
// We only emit warnings if the user has opted-in to Pulldown rendering.
1652
1673
let output = if render_type == RenderType :: Pulldown {
@@ -1665,10 +1686,7 @@ fn render_markdown(w: &mut fmt::Formatter, md_text: &str, render_type: RenderTyp
1665
1686
. collect :: < Vec < String > > ( ) ;
1666
1687
1667
1688
if !differences. is_empty ( ) {
1668
- // Emit warnings if there are differences.
1669
- println ! ( "Differences spotted in {:?}:\n {}" ,
1670
- md_text,
1671
- differences. join( "\n " ) ) ;
1689
+ scx. markdown_warnings . borrow_mut ( ) . push ( ( md_text. to_owned ( ) , differences) ) ;
1672
1690
}
1673
1691
1674
1692
pulldown_output
@@ -1680,15 +1698,15 @@ fn render_markdown(w: &mut fmt::Formatter, md_text: &str, render_type: RenderTyp
1680
1698
}
1681
1699
1682
1700
fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
1683
- render_type : RenderType , prefix : & str ) -> fmt:: Result {
1701
+ cx : & Context , prefix : & str ) -> fmt:: Result {
1684
1702
if let Some ( s) = item. doc_value ( ) {
1685
1703
let markdown = if s. contains ( '\n' ) {
1686
1704
format ! ( "{} [Read more]({})" ,
1687
1705
& plain_summary_line( Some ( s) ) , naive_assoc_href( item, link) )
1688
1706
} else {
1689
1707
format ! ( "{}" , & plain_summary_line( Some ( s) ) )
1690
1708
} ;
1691
- render_markdown ( w, & markdown, render_type, prefix) ?;
1709
+ render_markdown ( w, & markdown, cx . render_type , prefix, & cx . shared ) ?;
1692
1710
} else if !prefix. is_empty ( ) {
1693
1711
write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
1694
1712
}
@@ -1710,9 +1728,9 @@ fn render_assoc_const_value(item: &clean::Item) -> String {
1710
1728
}
1711
1729
1712
1730
fn document_full ( w : & mut fmt:: Formatter , item : & clean:: Item ,
1713
- render_type : RenderType , prefix : & str ) -> fmt:: Result {
1731
+ cx : & Context , prefix : & str ) -> fmt:: Result {
1714
1732
if let Some ( s) = item. doc_value ( ) {
1715
- render_markdown ( w, s, render_type, prefix) ?;
1733
+ render_markdown ( w, s, cx . render_type , prefix, & cx . shared ) ?;
1716
1734
} else if !prefix. is_empty ( ) {
1717
1735
write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
1718
1736
}
@@ -3111,20 +3129,20 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
3111
3129
// because impls can't have a stability.
3112
3130
document_stability ( w, cx, it) ?;
3113
3131
if item. doc_value ( ) . is_some ( ) {
3114
- document_full ( w, item, cx. render_type , & prefix) ?;
3132
+ document_full ( w, item, cx, & prefix) ?;
3115
3133
} else {
3116
3134
// In case the item isn't documented,
3117
3135
// provide short documentation from the trait.
3118
- document_short ( w, it, link, cx. render_type , & prefix) ?;
3136
+ document_short ( w, it, link, cx, & prefix) ?;
3119
3137
}
3120
3138
}
3121
3139
} else {
3122
3140
document_stability ( w, cx, item) ?;
3123
- document_full ( w, item, cx. render_type , & prefix) ?;
3141
+ document_full ( w, item, cx, & prefix) ?;
3124
3142
}
3125
3143
} else {
3126
3144
document_stability ( w, cx, item) ?;
3127
- document_short ( w, item, link, cx. render_type , & prefix) ?;
3145
+ document_short ( w, item, link, cx, & prefix) ?;
3128
3146
}
3129
3147
}
3130
3148
Ok ( ( ) )
0 commit comments