@@ -19,10 +19,15 @@ use rustc::session::search_paths::SearchPaths;
19
19
use rustc:: session:: config:: Externs ;
20
20
use syntax:: codemap:: DUMMY_SP ;
21
21
22
+ use clean:: Span ;
23
+
22
24
use externalfiles:: { ExternalHtml , LoadStringError , load_string} ;
23
25
26
+ use html_diff;
27
+
24
28
use html:: render:: reset_ids;
25
29
use html:: escape:: Escape ;
30
+ use html:: render:: { USED_ID_MAP , render_difference} ;
26
31
use html:: markdown;
27
32
use html:: markdown:: { Markdown , MarkdownWithToc , find_testable_code, old_find_testable_code} ;
28
33
use html:: markdown:: RenderType ;
@@ -52,6 +57,10 @@ fn extract_leading_metadata<'a>(s: &'a str) -> (Vec<&'a str>, &'a str) {
52
57
pub fn render ( input : & str , mut output : PathBuf , matches : & getopts:: Matches ,
53
58
external_html : & ExternalHtml , include_toc : bool ,
54
59
render_type : RenderType ) -> isize {
60
+ // Span used for markdown hoedown/pulldown differences.
61
+ let mut span = Span :: empty ( ) ;
62
+ span. filename = input. to_owned ( ) ;
63
+
55
64
let input_p = Path :: new ( input) ;
56
65
output. push ( input_p. file_stem ( ) . unwrap ( ) ) ;
57
66
output. set_extension ( "html" ) ;
@@ -89,12 +98,44 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
89
98
90
99
reset_ids ( false ) ;
91
100
92
- let rendered = if include_toc {
93
- format ! ( "{}" , MarkdownWithToc ( text, render_type) )
101
+ let ( hoedown_output, pulldown_output) = if include_toc {
102
+ // Save the state of USED_ID_MAP so it only gets updated once even
103
+ // though we're rendering twice.
104
+ let orig_used_id_map = USED_ID_MAP . with ( |map| map. borrow ( ) . clone ( ) ) ;
105
+ let hoedown_output = format ! ( "{}" , MarkdownWithToc ( text, RenderType :: Hoedown ) ) ;
106
+ USED_ID_MAP . with ( |map| * map. borrow_mut ( ) = orig_used_id_map) ;
107
+ let pulldown_output = format ! ( "{}" , MarkdownWithToc ( text, RenderType :: Pulldown ) ) ;
108
+ ( hoedown_output, pulldown_output)
94
109
} else {
95
- format ! ( "{}" , Markdown ( text, render_type) )
110
+ // Save the state of USED_ID_MAP so it only gets updated once even
111
+ // though we're rendering twice.
112
+ let orig_used_id_map = USED_ID_MAP . with ( |map| map. borrow ( ) . clone ( ) ) ;
113
+ let hoedown_output = format ! ( "{}" , Markdown ( text, RenderType :: Hoedown ) ) ;
114
+ USED_ID_MAP . with ( |map| * map. borrow_mut ( ) = orig_used_id_map) ;
115
+ let pulldown_output = format ! ( "{}" , Markdown ( text, RenderType :: Pulldown ) ) ;
116
+ ( hoedown_output, pulldown_output)
96
117
} ;
97
118
119
+ let mut differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
120
+ differences. retain ( |s| {
121
+ match * s {
122
+ html_diff:: Difference :: NodeText { ref elem_text,
123
+ ref opposite_elem_text,
124
+ .. }
125
+ if elem_text. split_whitespace ( ) . eq ( opposite_elem_text. split_whitespace ( ) ) => {
126
+ false
127
+ }
128
+ _ => true ,
129
+ }
130
+ } ) ;
131
+
132
+ if !differences. is_empty ( ) {
133
+ let mut intro_msg = false ;
134
+ for diff in differences {
135
+ render_difference ( & diff, & mut intro_msg, & span, text) ;
136
+ }
137
+ }
138
+
98
139
let err = write ! (
99
140
& mut out,
100
141
r#"<!DOCTYPE html>
@@ -126,16 +167,16 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
126
167
css = css,
127
168
in_header = external_html. in_header,
128
169
before_content = external_html. before_content,
129
- text = rendered ,
170
+ text = if render_type == RenderType :: Pulldown { pulldown_output } else { hoedown_output } ,
130
171
after_content = external_html. after_content,
131
- ) ;
172
+ ) ;
132
173
133
174
match err {
134
175
Err ( e) => {
135
176
eprintln ! ( "rustdoc: cannot write to `{}`: {}" , output. display( ) , e) ;
136
177
6
137
178
}
138
- Ok ( _) => 0
179
+ Ok ( _) => 0 ,
139
180
}
140
181
}
141
182
0 commit comments