@@ -15,8 +15,8 @@ use url::Url;
1515use crate :: cache:: Cache ;
1616use crate :: cookies:: Cookie ;
1717use crate :: html:: {
18- add_favicon, create_metadata_tag, get_base_url, get_charset, has_favicon , html_to_dom ,
19- serialize_document, set_base_url, set_charset, walk_and_embed_assets,
18+ add_favicon, create_metadata_tag, get_base_url, get_charset, get_title , has_favicon ,
19+ html_to_dom , serialize_document, set_base_url, set_charset, walk_and_embed_assets,
2020} ;
2121use crate :: url:: { clean_url, create_data_url, get_referer_url, parse_data_url, resolve_url} ;
2222
@@ -122,7 +122,7 @@ pub fn create_monolithic_document(
122122 source : String ,
123123 options : & Options ,
124124 cache : & mut Option < Cache > ,
125- ) -> Result < Vec < u8 > , MonolithError > {
125+ ) -> Result < ( Vec < u8 > , Option < String > ) , MonolithError > {
126126 // Check if source was provided
127127 if source. is_empty ( ) {
128128 return Err ( MonolithError :: new ( "no target specified" ) ) ;
@@ -235,7 +235,7 @@ pub fn create_monolithic_document(
235235 if !media_type. eq_ignore_ascii_case ( "text/html" )
236236 && !media_type. eq_ignore_ascii_case ( "application/xhtml+xml" )
237237 {
238- return Ok ( retrieved_data) ;
238+ return Ok ( ( retrieved_data, None ) ) ;
239239 }
240240
241241 if options
@@ -353,6 +353,8 @@ pub fn create_monolithic_document(
353353 dom = set_charset ( dom, document_encoding. clone ( ) ) ;
354354 }
355355
356+ let document_title: Option < String > = get_title ( & dom. document ) ;
357+
356358 if options. output_format == MonolithOutputFormat :: HTML {
357359 // Serialize DOM tree
358360 let mut result: Vec < u8 > = serialize_document ( dom, document_encoding, options) ;
@@ -364,9 +366,9 @@ pub fn create_monolithic_document(
364366 result. splice ( 0 ..0 , metadata_comment. as_bytes ( ) . to_vec ( ) ) ;
365367 }
366368
367- Ok ( result)
369+ Ok ( ( result, document_title ) )
368370 } else {
369- Ok ( vec ! [ ] )
371+ Ok ( ( vec ! [ ] , document_title ) )
370372 }
371373}
372374
0 commit comments