r-markdownmarkdownpandocquartoreveal.js

How to Automatically Apply Section Headings to Slides in Quarto Reveal.js Presentations?


I’m working on a Quarto presentation using Reveal.js, and I’m trying to automate the process of applying section headings to all slides within a section. Specifically, I want each slide under a particular section heading (e.g., ## animal) to automatically display that heading, without manually repeating it on each slide.

Here’s a simplified version of my Quarto presentation file:

---
title: "Dummy title"
format: revealjs
slide-level: 2
---

## animal

- slide 1

---

- slide 2

---

- slide 3

## fruits

- slide 4

---

- slide 5

Desired Behavior:

All slides under ## animal should display "animal" as a heading.
All slides under ## fruits should display "fruits" as a heading.
I want this to be done dynamically without manually inserting the section heading into each slide.

I’ve been unable to find a straightforward method to automatically apply the section heading to each slide within that section in Quarto. Is there a built-in way in Quarto or Reveal.js to achieve this, or is there a recommended workaround that could simplify this process?


Solution

  • I have created an Quarto filter extension reveal-autoheader in response to this question. Usage is simple. Install the filter in your presentation directory and use the filter.

    ---
    title: "Dummy title"
    format: revealjs
    slide-level: 2
    filters:
      - reveal-autoheader
    ---
    
    ## Animal
    
    - slide 1
    
    ---
    
    - slide 2
    
    ---
    
    - slide 3
    
    ## Fruits
    
    - slide 4
    
    ---
    
    - slide 5
    

    Rendered Output Overview Screenshot