1
Fork 0

Parse max-level

This commit is contained in:
Jan-Erik Rediger 2021-01-06 14:39:52 +01:00
parent 6e8b632a30
commit 8916d17e4b

View file

@ -17,12 +17,14 @@ static DEFAULT_MARKER: &str = "<!-- toc -->\n";
struct Config { struct Config {
marker: String, marker: String,
max_level: u32,
} }
impl Default for Config { impl Default for Config {
fn default() -> Config { fn default() -> Config {
Config { Config {
marker: DEFAULT_MARKER.into(), marker: DEFAULT_MARKER.into(),
max_level: 4,
} }
} }
} }
@ -50,6 +52,19 @@ impl<'a> TryFrom<Option<&'a Table>> for Config {
cfg.marker = marker.into(); cfg.marker = marker.into();
} }
if let Some(level) = mdbook_cfg.get("max-level") {
let level = match level.as_integer() {
Some(l) => l,
None => {
return Err(Error::msg(format!(
"Level {:?} is not a valid integer",
level
)))
}
};
cfg.max_level = level.try_into()?;
}
Ok(cfg) Ok(cfg)
} }
} }