Skip to content

Commit

Permalink
feat: disabled flag to disable rendering even if mdbook-pandoc is…
Browse files Browse the repository at this point in the history
… available (#93)

Adds a `disabled` flag to disable rendering even if `mdbook-pandoc` is
available. Since rendering may rely on external dependencies, this can
be used to e.g. disable rendering except in CI where needed dependencies
are known to be installed.

Related to
google/mdbook-i18n-helpers#200 (comment)
  • Loading branch information
max-heller authored Jul 10, 2024
1 parent de33b6d commit a10f175
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ use preprocess::Preprocessor;
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
struct Config {
#[serde(rename = "profile")]
#[serde(rename = "profile", default = "Default::default")]
pub profiles: HashMap<String, pandoc::Profile>,
#[serde(default = "defaults::enabled")]
pub keep_preprocessed: bool,
pub hosted_html: Option<String>,
/// Code block related configuration.
#[serde(default = "Default::default")]
pub code: CodeConfig,
/// Skip running the renderer.
#[serde(default = "Default::default")]
pub disabled: bool,
}

/// Configuration for tweaking how code blocks are rendered.
Expand Down Expand Up @@ -97,6 +100,11 @@ impl mdbook::Renderer for Renderer {
.with_context(|| format!("Unable to deserialize {}", Self::CONFIG_KEY))?
.ok_or(anyhow!("No {} table found", Self::CONFIG_KEY))?;

if cfg.disabled {
log::info!("Skipping rendering since `disabled` is set");
return Ok(());
}

let html_cfg: Option<HtmlConfig> = ctx
.config
.get_deserialized_opt("output.html")
Expand Down Expand Up @@ -1410,6 +1418,22 @@ colorlinks = false
"###)
}

#[test]
fn disabled() {
let cfg = r#"
[output.pandoc]
disabled = true
"#;
let output = MDBook::init()
.mdbook_config(mdbook::Config::from_str(cfg).unwrap())
.build();
insta::assert_snapshot!(output, @r###"
├─ log output
│ INFO mdbook::book: Running the pandoc backend
│ INFO mdbook_pandoc: Skipping rendering since `disabled` is set
"###)
}

#[test]
fn redirects() {
let cfg = r#"
Expand Down

0 comments on commit a10f175

Please sign in to comment.