Presentation

class respysive.Presentation[source]

Bases: object

Presentation container for creating HTML slideshows.

Creates interactive presentations using Bootstrap and the respysive runtime (navigation, fragments, speaker notes, overflow fitting). Supports global data sharing and multiple content types.

add_global_geojson(div_id, geojson_data)[source]

Add global GeoJSON data for sharing across slides.

Parameters:
  • div_id – Unique identifier for the GeoJSON data

  • geojson_data – GeoJSON as a dictionary, a JSON string, or the path of a .geojson/.json file

Raises:
  • TypeError – If geojson_data is not a dict, a string or a path.

  • FileNotFoundError – If geojson_data is a path to a missing file.

add_custom_css(css)[source]

Add custom CSS to the presentation.

Injects custom CSS into the HTML <head> for styling, overlays, or watermarks. CSS is applied to all slides in the presentation.

Parameters:

css (str) – CSS code as string

Example

Add a logo overlay to slides with the ‘branded’ class:

presentation.add_custom_css('''
    .slides section.branded::after {
        content: '';
        position: absolute;
        top: 20px;
        right: 20px;
        width: 100px;
        height: 100px;
        background-image: url('logo.svg');
        background-size: contain;
        opacity: 0.7;
        pointer-events: none;
        z-index: 10;
    }
''')

slide = Slide(**{'class': 'branded'})
add_library(name=None, js=None, css=None)[source]

Load an extra library, either built-in or from your own URLs.

Built-in libraries are normally detected from the slides; naming one forces it. URLs are loaded in the order given, after built-in libraries, and are embedded like the others by offline=True.

Parameters:
  • name – Built-in library to force (‘plotly’, ‘vega’, ‘d3’, ‘mathjax’, ‘maplibre’, ‘fontawesome’).

  • js – Script URL(s) or local path(s).

  • css – Stylesheet URL(s) or local path(s).

Raises:

ValueError – If name is not a built-in library and no URL is given.

Example:

presentation.add_library("mathjax")
presentation.add_library(
    js="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js",
    css=["https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"],
)
add_slide(slide)[source]

Add slide or slides to the presentation.

Parameters:

slide – Slide object or list of Slide objects (a nested list creates a vertical stack)

to_html(theme='moon', width=1280, height=720, minscale=0.2, maxscale=2.0, margin=0.04, custom_theme=None, center=True, embedded=False, transition='slide', overflow='fit', controls=True, progress=True, slide_number='c/t', libraries='auto', offline=False)[source]

Generate the full HTML document for the presentation.

Parameters:
  • theme – ‘sober’, ‘science’ or ‘corporate’ for a respysive theme, which also gives Plotly and Altair charts its colours and font. Otherwise a Reveal.js theme name (e.g. ‘moon’, ‘white’, ‘black’), of which only the CSS is used. Use ‘custom’ with custom_theme for external CSS, or None for no theme.

  • width – Slide width in pixels. Default 1280.

  • height – Slide height in pixels. Default 720.

  • minscale – Minimum scaling factor. Default 0.2.

  • maxscale – Maximum scaling factor. Default 2.0.

  • margin – Margin around slides as a fraction of the window (0.0 to 0.5). Default 0.04.

  • custom_theme – URL to custom CSS theme file. Required when theme=’custom’.

  • center – Vertically center slide content. Default True.

  • embedded – Size the deck to its parent element instead of the window. Default False.

  • transition – Slide transition: ‘slide’, ‘fade’ or ‘none’. Default ‘slide’.

  • overflow – Default handling of content taller than the slide, overridable per slide: ‘fit’ shrinks text then scales content to fit, ‘warn’ logs overflowing slides in the browser console, ‘visible’ does nothing.

  • controls – Show navigation arrows. Default True.

  • progress – Show the progress bar. Default True.

  • slide_number – Slide number format: ‘c/t’, ‘c’, ‘h.v’, ‘h/v’, or None to hide it.

  • libraries – Built-in libraries to load: ‘auto’ (those the slides use, plus add_library() names), ‘all’, or a list of names. Bootstrap is always loaded.

  • offline – Embed every script, stylesheet and font in the HTML file so it opens without network. Files are cached locally on first download; run respysive.download_libraries() beforehand to work fully offline. Map tiles and remote images still need the network.

Returns:

str – Complete HTML document as string.

Raises:

ValueError – If theme is ‘custom’ but custom_theme is not provided, or if transition / overflow is not a supported value.

save_html(file_name, **kwargs)
save_pdf(file_name, *args, **kwargs)
check(min_scale=0.7, timeout=60, **kwargs)[source]

Render the deck in headless Chromium and report how each slide fits.

The report lists, for each slide, the scale of its text after fitting, what becomes a picture in a PowerPoint export, and the hosts the deck loads resources from. Printing it gives a table. Requires Playwright and Chromium, like the exports.

Parameters:
  • min_scale – Text scale under which a slide counts as too small.

  • timeout – Seconds allowed for loading charts, equations and maps

  • **kwargs – Arguments to pass to to_html(), as for save_html()

Returns:

respysive.report.DeckReport

Example

>>> report = deck.check(theme="white")
>>> print(report)
>>> slides_to_split = [s.number for s in report.small]
save_pptx(file_name, *args, **kwargs)
class respysive.report.DeckReport(slides, min_scale, network)[source]

Bases: object

Result of Presentation.check().

Variables:
  • slides – One SlideReport per slide, in order.

  • min_scale – Readability threshold used for small.

  • network (list[str]) – Hosts the deck loaded resources from. Empty for a deck that works offline.

slides: list[SlideReport]
min_scale: float
network: list[str]
property small: list[SlideReport]

Slides whose text was shrunk below min_scale.

property overflowing: list[SlideReport]

Slides whose content runs past the bottom (fitting turned off).

property ok: bool

True when every slide fits and stays readable.

class respysive.report.SlideReport(number, title, scale=1.0, overflow=None, pictures=list())[source]

Bases: object

How one slide renders.

Variables:
  • number (str) – Slide number as shown in the deck, “3” or “3.2” in a vertical stack.

  • title (str) – Text of the first heading, empty when the slide has none.

  • scale (float) – Size of the text relative to its normal size, after fitting (1 when nothing was shrunk).

  • overflow (float | None) – With overflow="warn", the height of the content relative to the slide when it does not fit, else None.

  • pictures (list[str]) – What becomes a picture in the PowerPoint export (“Plotly chart”, “MapLibre map”, “equation”, …). Plotly charts simple enough are rebuilt as native charts instead.

number: str
title: str
scale: float = 1.0
overflow: float | None = None
pictures: list[str]