@@ -75,6 +75,8 @@ use html::item_type::ItemType;
7575use html:: markdown:: { self , Markdown , MarkdownHtml , MarkdownSummaryLine , RenderType } ;
7676use html:: { highlight, layout} ;
7777
78+ use html_diff;
79+
7880/// A pair of name and its optional document.
7981pub type NameDoc = ( String , Option < String > ) ;
8082
@@ -1643,6 +1645,33 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re
16431645 Ok ( ( ) )
16441646}
16451647
1648+ fn get_html_diff ( w : & mut fmt:: Formatter , md_text : & str , render_type : RenderType ,
1649+ prefix : & str ) -> fmt:: Result {
1650+ let output = format ! ( "{}" , Markdown ( md_text, render_type) ) ;
1651+ let old = format ! ( "{}" , Markdown ( md_text, match render_type {
1652+ RenderType :: Hoedown => RenderType :: Pulldown ,
1653+ RenderType :: Pulldown => RenderType :: Hoedown ,
1654+ } ) ) ;
1655+ let differences = html_diff:: get_differences ( & output, & old) ;
1656+ if !differences. is_empty ( ) {
1657+ println ! ( "Differences spotted in {:?}:\n {}" ,
1658+ md_text,
1659+ differences. iter( )
1660+ . filter_map( |s| {
1661+ match * s {
1662+ html_diff:: Difference :: NodeText { ref elem_text,
1663+ ref opposite_elem_text,
1664+ .. }
1665+ if elem_text. trim( ) == opposite_elem_text. trim( ) => None ,
1666+ _ => Some ( format!( "=> {}" , s. to_string( ) ) ) ,
1667+ }
1668+ } )
1669+ . collect:: <Vec <String >>( )
1670+ . join( "\n " ) ) ;
1671+ }
1672+ write ! ( w, "<div class='docblock'>{}{}</div>" , prefix, output)
1673+ }
1674+
16461675fn document_short ( w : & mut fmt:: Formatter , item : & clean:: Item , link : AssocItemLink ,
16471676 render_type : RenderType , prefix : & str ) -> fmt:: Result {
16481677 if let Some ( s) = item. doc_value ( ) {
@@ -1652,7 +1681,7 @@ fn document_short(w: &mut fmt::Formatter, item: &clean::Item, link: AssocItemLin
16521681 } else {
16531682 format ! ( "{}" , & plain_summary_line( Some ( s) ) )
16541683 } ;
1655- write ! ( w, "<div class='docblock'>{}{}</div>" , prefix , Markdown ( & markdown, render_type) ) ?;
1684+ get_html_diff ( w, & markdown, render_type, prefix ) ?;
16561685 } else if !prefix. is_empty ( ) {
16571686 write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
16581687 }
@@ -1676,7 +1705,7 @@ fn render_assoc_const_value(item: &clean::Item) -> String {
16761705fn document_full ( w : & mut fmt:: Formatter , item : & clean:: Item ,
16771706 render_type : RenderType , prefix : & str ) -> fmt:: Result {
16781707 if let Some ( s) = item. doc_value ( ) {
1679- write ! ( w, "<div class='docblock'>{}{}</div>" , prefix , Markdown ( s, render_type) ) ?;
1708+ get_html_diff ( w, s, render_type, prefix ) ?;
16801709 } else if !prefix. is_empty ( ) {
16811710 write ! ( w, "<div class='docblock'>{}</div>" , prefix) ?;
16821711 }
0 commit comments