@@ -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
24
- use html:: render:: reset_ids;
26
+ use html_diff;
27
+
28
+ use html:: render:: { render_text, reset_ids} ;
25
29
use html:: escape:: Escape ;
30
+ use html:: render:: 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,36 @@ 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
+ render_text ( |ty| format ! ( "{}" , MarkdownWithToc ( text, ty) ) )
94
105
} else {
95
- format ! ( "{}" , Markdown ( text, render_type) )
106
+ // Save the state of USED_ID_MAP so it only gets updated once even
107
+ // though we're rendering twice.
108
+ render_text ( |ty| format ! ( "{}" , Markdown ( text, ty) ) )
96
109
} ;
97
110
111
+ let mut differences = html_diff:: get_differences ( & pulldown_output, & hoedown_output) ;
112
+ differences. retain ( |s| {
113
+ match * s {
114
+ html_diff:: Difference :: NodeText { ref elem_text,
115
+ ref opposite_elem_text,
116
+ .. }
117
+ if elem_text. split_whitespace ( ) . eq ( opposite_elem_text. split_whitespace ( ) ) => {
118
+ false
119
+ }
120
+ _ => true ,
121
+ }
122
+ } ) ;
123
+
124
+ if !differences. is_empty ( ) {
125
+ let mut intro_msg = false ;
126
+ for diff in differences {
127
+ render_difference ( & diff, & mut intro_msg, & span, text) ;
128
+ }
129
+ }
130
+
98
131
let err = write ! (
99
132
& mut out,
100
133
r#"<!DOCTYPE html>
@@ -126,16 +159,16 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
126
159
css = css,
127
160
in_header = external_html. in_header,
128
161
before_content = external_html. before_content,
129
- text = rendered ,
162
+ text = if render_type == RenderType :: Pulldown { pulldown_output } else { hoedown_output } ,
130
163
after_content = external_html. after_content,
131
- ) ;
164
+ ) ;
132
165
133
166
match err {
134
167
Err ( e) => {
135
168
eprintln ! ( "rustdoc: cannot write to `{}`: {}" , output. display( ) , e) ;
136
169
6
137
170
}
138
- Ok ( _) => 0
171
+ Ok ( _) => 0 ,
139
172
}
140
173
}
141
174
0 commit comments