diff --git a/nbconvert/exporters/slides.py b/nbconvert/exporters/slides.py index 545c623c9..3d9c21e22 100644 --- a/nbconvert/exporters/slides.py +++ b/nbconvert/exporters/slides.py @@ -183,3 +183,35 @@ def _init_resources(self, resources): resources["reveal"]["scroll"] = self.reveal_scroll resources["reveal"]["number"] = self.reveal_number return resources + + def from_notebook_node(self, nb, resources=None, **kw): + """ + Convert a notebook from a notebook node instance. + This method extends the parent implementation to override reveal.js + configuration with metadata from the notebook. + It reads reveal.js settings from the `reveal` key in the notebook's + metadata and merges them with the existing configuration. + The precedence for settings is: + 1. Command-line arguments (highest) + 2. Notebook metadata + 3. Default configuration (lowest) + Parameters + ---------- + nb : :class:`~nbformat.NotebookNode` + Notebook node + resources : dict + Additional resources that can be accessed by exporters and preprocessors. + """ + output, resources = super().from_notebook_node(nb, resources, **kw) + if "reveal" in nb.metadata: + self.log.info("Applying reveal config from notebook metadata") + # Get reveal config from notebook metadata. + nb_reveal_config = nb.metadata.get("reveal", {}) + + # `resources['reveal']` contains config from command line. + # We merge the two, with command-line config having precedence. + reveal_config = nb_reveal_config.copy() + reveal_config.update(resources.get("reveal", {})) + resources["reveal"] = reveal_config + + return output, resources