@@ -28,7 +28,7 @@ impl HtmlHandlebars {
28
28
}
29
29
30
30
fn render_item ( & self , item : & BookItem , book : & MDBook , data : & mut serde_json:: Map < String , serde_json:: Value > ,
31
- print_content : & mut String , handlebars : & mut Handlebars , index : & mut bool )
31
+ print_content : & mut String , handlebars : & mut Handlebars , index : & mut bool , destination : & Path )
32
32
-> Result < ( ) , Box < Error > > {
33
33
match * item {
34
34
BookItem :: Chapter ( _, ref ch) |
@@ -66,15 +66,10 @@ impl HtmlHandlebars {
66
66
// Render the handlebars template with the data
67
67
debug ! ( "[*]: Render template" ) ;
68
68
let rendered = handlebars. render ( "index" , & data) ?;
69
+ let rendered = self . post_processing ( rendered) ;
69
70
70
71
let filename = Path :: new ( & ch. path ) . with_extension ( "html" ) ;
71
72
72
- // Do several kinds of post-processing
73
- let rendered = build_header_links ( rendered, filename. to_str ( ) . unwrap_or ( "" ) ) ;
74
- let rendered = fix_anchor_links ( rendered, filename. to_str ( ) . unwrap_or ( "" ) ) ;
75
- let rendered = fix_code_blocks ( rendered) ;
76
- let rendered = add_playpen_pre ( rendered) ;
77
-
78
73
// Write to file
79
74
info ! ( "[*] Creating {:?} ✓" , filename. display( ) ) ;
80
75
book. write_file ( filename, & rendered. into_bytes ( ) ) ?;
@@ -86,9 +81,7 @@ impl HtmlHandlebars {
86
81
let mut content = String :: new ( ) ;
87
82
88
83
let _source = File :: open (
89
- book. get_destination ( )
90
- . expect ( "If the HTML renderer is called, one would assume the HtmlConfig is set... (3)" )
91
- . join ( & ch. path . with_extension ( "html" ) )
84
+ destination. join ( & ch. path . with_extension ( "html" ) )
92
85
) ?. read_to_string ( & mut content) ;
93
86
94
87
// This could cause a problem when someone displays
@@ -148,7 +141,6 @@ impl HtmlHandlebars {
148
141
Ok ( ( ) )
149
142
}
150
143
151
-
152
144
fn write_custom_file ( & self , custom_file : & Path , book : & MDBook ) -> Result < ( ) , Box < Error > > {
153
145
let mut data = Vec :: new ( ) ;
154
146
let mut f = File :: open ( custom_file) ?;
@@ -200,10 +192,8 @@ impl Renderer for HtmlHandlebars {
200
192
debug ! ( "[fn]: render" ) ;
201
193
let mut handlebars = Handlebars :: new ( ) ;
202
194
203
- // Load theme
204
195
let theme = theme:: Theme :: new ( book. get_theme_path ( ) ) ;
205
196
206
- // Register template
207
197
debug ! ( "[*]: Register handlebars template" ) ;
208
198
handlebars
209
199
. register_template_string ( "index" , String :: from_utf8 ( theme. index . clone ( ) ) ?) ?;
@@ -214,20 +204,20 @@ impl Renderer for HtmlHandlebars {
214
204
let mut data = make_data ( book) ?;
215
205
216
206
// Print version
217
- let mut print_content: String = String :: new ( ) ;
207
+ let mut print_content = String :: new ( ) ;
218
208
219
- debug ! ( "[*]: Check if destination directory exists" ) ;
220
209
let destination = book. get_destination ( )
221
210
. expect ( "If the HTML renderer is called, one would assume the HtmlConfig is set... (2)" ) ;
222
211
212
+ debug ! ( "[*]: Check if destination directory exists" ) ;
223
213
if fs:: create_dir_all ( & destination) . is_err ( ) {
224
214
return Err ( Box :: new ( io:: Error :: new ( io:: ErrorKind :: Other ,
225
215
"Unexpected error when constructing destination path" ) ) ) ;
226
216
}
227
217
228
218
let mut index = true ;
229
219
for item in book. iter ( ) {
230
- self . render_item ( item, book, & mut data, & mut print_content, & mut handlebars, & mut index) ?;
220
+ self . render_item ( item, book, & mut data, & mut print_content, & mut handlebars, & mut index, & destination ) ?;
231
221
}
232
222
233
223
// Print version
0 commit comments