nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

Reveal.js slideshow export should skip `{ "slide_type": "-" }` cells

Open ryan-williams opened this issue 1 year ago • 1 comments

_RevealMetadataPreprocessor currently:

  1. gives every cell a slide_type of "-" (if one isn't explicitly set; source)
  2. concatenates consecutive { "slide_type": "-" } cells into one slide (source)

This leads to poor / unexpected behavior in a few ways:

Slides overflow the viewport vertically, with no ability to scroll

For example, test_slides.py::test_export converts notebook2.ipynb (which contains no slideshow metadata), and only verifies that the resulting HTML string has length > 0.

Here is a demo of that exported slideshow:

Screenshot

image

It's one slide, with all cells concatenated, but you can't scroll down to see more than the first couple cells (e.g. Out[7] at the bottom is cut off, on my screen, as shown above, with no way to see more).

Possible workarounds

  • Reveal.js 5.x includes a "Scroll View," but this is different from the Reveal.js look and feel most folks are used to.
  • It's possible to add custom CSS/JS/jquery to the page to modify how overflowing slides are handled (SO example), but it's nontrivial, and the default experience with nbconvert is suboptimal.

It's tedious to only export certain cells (all cells must be manually marked "Skip")

Avoiding having every cell get concatenated into an overflowing, unscrollable cell requires manually setting each cell's "Slide Type" to "Skip".

You can select multiple cells and try to set them all to "Skip" in bulk, but it only sets the first one, due to https://github.com/jupyterlab/jupyterlab/issues/5895.

Cells should be skipped by default

The simplest / least surprising default, to me, would be to skip cells that are not marked as "Slide", "Subslide", or "Fragment."

As it stands, there is an undocumented type "-", which is the default, translates to "concatenate into the previous/current slide," frequently results in a broken user experience, and cannot be changed in bulk (via the GUI).

ryan-williams avatar Nov 09 '23 16:11 ryan-williams

Temporary workaround:

import nbformat

# Load your notebook
notebook_path = '/home/roberto/Github/Transcriptomics-5-HT/Figure 1b.ipynb'  # Replace with your notebook path
with open(notebook_path, 'r', encoding='utf-8') as f:
    nb = nbformat.read(f, as_version=4)

# Modify all cells
for cell in nb.cells:
    if 'metadata' not in cell:
        cell['metadata'] = {}
    cell['metadata']['slideshow'] = {'slide_type': 'skip'}

# Save the modified notebook
with open(notebook_path, 'w', encoding='utf-8') as f:
    nbformat.write(nb, f)

print("All cells have been set to slide type 'skip'")

RobertoDF avatar Nov 14 '23 19:11 RobertoDF