@@ -226,39 +226,6 @@ impl Config {
226
226
227
227
Ok ( ( ) )
228
228
}
229
-
230
- fn from_legacy ( mut table : Value ) -> Config {
231
- let mut cfg = Config :: default ( ) ;
232
-
233
- // we use a macro here instead of a normal loop because the $out
234
- // variable can be different types. This way we can make type inference
235
- // figure out what try_into() deserializes to.
236
- macro_rules! get_and_insert {
237
- ( $table: expr, $key: expr => $out: expr) => {
238
- let got = $table
239
- . as_table_mut( )
240
- . and_then( |t| t. remove( $key) )
241
- . and_then( |v| v. try_into( ) . ok( ) ) ;
242
- if let Some ( value) = got {
243
- $out = value;
244
- }
245
- } ;
246
- }
247
-
248
- get_and_insert ! ( table, "title" => cfg. book. title) ;
249
- get_and_insert ! ( table, "authors" => cfg. book. authors) ;
250
- get_and_insert ! ( table, "source" => cfg. book. src) ;
251
- get_and_insert ! ( table, "description" => cfg. book. description) ;
252
-
253
- if let Some ( dest) = table. delete ( "output.html.destination" ) {
254
- if let Ok ( destination) = dest. try_into ( ) {
255
- cfg. build . build_dir = destination;
256
- }
257
- }
258
-
259
- cfg. rest = table;
260
- cfg
261
- }
262
229
}
263
230
264
231
impl Default for Config {
@@ -276,18 +243,6 @@ impl<'de> serde::Deserialize<'de> for Config {
276
243
fn deserialize < D : Deserializer < ' de > > ( de : D ) -> std:: result:: Result < Self , D :: Error > {
277
244
let raw = Value :: deserialize ( de) ?;
278
245
279
- if is_legacy_format ( & raw ) {
280
- warn ! ( "It looks like you are using the legacy book.toml format." ) ;
281
- warn ! ( "We'll parse it for now, but you should probably convert to the new format." ) ;
282
- warn ! ( "See the mdbook documentation for more details, although as a rule of thumb" ) ;
283
- warn ! ( "just move all top level configuration entries like `title`, `author` and" ) ;
284
- warn ! ( "`description` under a table called `[book]`, move the `destination` entry" ) ;
285
- warn ! ( "from `[output.html]`, renamed to `build-dir`, under a table called" ) ;
286
- warn ! ( "`[build]`, and it should all work." ) ;
287
- warn ! ( "Documentation: https://rust-lang.github.io/mdBook/format/config.html" ) ;
288
- return Ok ( Config :: from_legacy ( raw) ) ;
289
- }
290
-
291
246
warn_on_invalid_fields ( & raw ) ;
292
247
293
248
use serde:: de:: Error ;
@@ -365,24 +320,6 @@ fn warn_on_invalid_fields(table: &Value) {
365
320
}
366
321
}
367
322
368
- fn is_legacy_format ( table : & Value ) -> bool {
369
- let legacy_items = [
370
- "title" ,
371
- "authors" ,
372
- "source" ,
373
- "description" ,
374
- "output.html.destination" ,
375
- ] ;
376
-
377
- for item in & legacy_items {
378
- if table. read ( item) . is_some ( ) {
379
- return true ;
380
- }
381
- }
382
-
383
- false
384
- }
385
-
386
323
/// Configuration options which are specific to the book and required for
387
324
/// loading it from disk.
388
325
#[ derive( Debug , Clone , PartialEq , Serialize , Deserialize ) ]
@@ -1006,57 +943,6 @@ mod tests {
1006
943
assert_eq ! ( got_baz, baz_should_be) ;
1007
944
}
1008
945
1009
- /// The config file format has slightly changed (metadata stuff is now under
1010
- /// the `book` table instead of being at the top level) so we're adding a
1011
- /// **temporary** compatibility check. You should be able to still load the
1012
- /// old format, emitting a warning.
1013
- #[ test]
1014
- fn can_still_load_the_previous_format ( ) {
1015
- let src = r#"
1016
- title = "mdBook Documentation"
1017
- description = "Create book from markdown files. Like Gitbook but implemented in Rust"
1018
- authors = ["Mathieu David"]
1019
- source = "./source"
1020
-
1021
- [output.html]
1022
- destination = "my-book" # the output files will be generated in `root/my-book` instead of `root/book`
1023
- theme = "my-theme"
1024
- smart-punctuation = true
1025
- additional-css = ["custom.css", "custom2.css"]
1026
- additional-js = ["custom.js"]
1027
- "# ;
1028
-
1029
- let book_should_be = BookConfig {
1030
- title : Some ( String :: from ( "mdBook Documentation" ) ) ,
1031
- description : Some ( String :: from (
1032
- "Create book from markdown files. Like Gitbook but implemented in Rust" ,
1033
- ) ) ,
1034
- authors : vec ! [ String :: from( "Mathieu David" ) ] ,
1035
- src : PathBuf :: from ( "./source" ) ,
1036
- ..Default :: default ( )
1037
- } ;
1038
-
1039
- let build_should_be = BuildConfig {
1040
- build_dir : PathBuf :: from ( "my-book" ) ,
1041
- create_missing : true ,
1042
- use_default_preprocessors : true ,
1043
- extra_watch_dirs : Vec :: new ( ) ,
1044
- } ;
1045
-
1046
- let html_should_be = HtmlConfig {
1047
- theme : Some ( PathBuf :: from ( "my-theme" ) ) ,
1048
- smart_punctuation : true ,
1049
- additional_css : vec ! [ PathBuf :: from( "custom.css" ) , PathBuf :: from( "custom2.css" ) ] ,
1050
- additional_js : vec ! [ PathBuf :: from( "custom.js" ) ] ,
1051
- ..Default :: default ( )
1052
- } ;
1053
-
1054
- let got = Config :: from_str ( src) . unwrap ( ) ;
1055
- assert_eq ! ( got. book, book_should_be) ;
1056
- assert_eq ! ( got. build, build_should_be) ;
1057
- assert_eq ! ( got. html_config( ) . unwrap( ) , html_should_be) ;
1058
- }
1059
-
1060
946
#[ test]
1061
947
fn set_a_config_item ( ) {
1062
948
let mut cfg = Config :: default ( ) ;
0 commit comments