reveal.js HTML Presentation Framework

repository·master·Indexed 13 days ago

https://github.com/hakimel/reveal.js

An open-source HTML presentation framework for creating interactive presentations using HTML, CSS, and JavaScript. Features include nested vertical slides, Markdown support, Auto-Animate transitions, PDF export, speaker notes, LaTeX math typesetting, and syntax-highlighted code blocks. Includes a React wrapper (@revealjs/react) and plugins for Markdown and Highlight.js.

Tokens
11.9K
Snippets
39
Records
49
Agent score
99%

What's inside reveal.js

  1. Overview of reveal.js

    master
    reveal.js is an open source HTML presentation framework that allows you to create presentations using web technologies. It is designed to be viewed in any web browser and includes advanced features like nested (vertical) slides, Markdown support, Auto-Animate transitions, PDF export, speaker notes, LaTeX math typesetting, and syntax-highlighted code blocks.
  2. How @revealjs/react works

    master

    Understanding the lifecycle and synchronization of the wrapper:

    • Initialization: Deck creates one Reveal instance on mount and destroys it on unmount. Initialization is asynchronous; onReady fires once reveal.initialize() resolves. The instance becomes available via useReveal() and deckRef only after this point.
    • Synchronization: Deck calls reveal.sync() when the React slide structure changes (adding, removing, or reordering slides).
    • Slide Updates: Slide components handle local data-* attribute updates using reveal.syncSlide(). This allows React content updates inside a slide to occur without triggering a full deck sync.
    • Markdown: The Markdown component uses marked and supports standard Reveal markdown comment syntax (e.g., <!-- .slide: ... --> and <!-- .element: ... -->).
    • Configuration: The config prop is shallow-compared; reveal.configure() is only called when a value actually changes.
    • Plugins: The plugins prop is captured once on the first mount and ignored on subsequent renders, matching Reveal's initialization lifecycle.
  3. Set up a basic Reveal deck in React

    master

    To create a presentation, render a Deck component containing one or more Slide components. You must import the core Reveal CSS and a theme (e.g., black.css) for the deck to render correctly.

    import { Deck, Slide } from '@revealjs/react';
    import 'reveal.js/reveal.css';
    import 'reveal.js/theme/black.css';
    
    export function Presentation() {
      return (
        <Deck>
          <Slide>
            <h1>Hello</h1>
            <p>My first Reveal deck in React.</p>
          </Slide>
    
          <Slide background="#111827">
            <h2>Second slide</h2>
          </Slide>
        </Deck>
      );
    }
  4. How to create a custom reveal.js theme

    master

    To create a new theme, duplicate an existing .scss file located in css/theme. The theme will be automatically compiled from Sass to CSS when you execute the build command.

    Each theme follows a specific four-step structure based on template files:

    1. Include mixins.scss: Provides shared utility functions.
    2. Include settings.scss: Defines the custom CSS variables used by the template. You should override these variables to customize your theme's appearance.
    3. Include theme.scss: The core template file that generates the final CSS output based on the variables defined in the previous step.
    4. Customization: Optionally add custom fonts or additional specific styles at the end of the file.
    # To compile your new theme after creating the .scss file
    npm run build:styles
  5. Prerequisites for creating a reveal.js theme

    master
    Themes are written using Sass to maintain modularity and minimize selector repetition. Before attempting to create or modify themes, ensure you have the full reveal.js development environment installed as described in the official installation guide.
  6. Install @revealjs/react and dependencies

    master

    To use the React wrapper, install @revealjs/react along with its peer dependencies: reveal.js, react, and react-dom.

    Note: The package only provides React bindings. You are responsible for importing Reveal CSS, themes, and any plugins you intend to use.

    npm i @revealjs/react reveal.js react react-dom
    # or
    yarn add @revealjs/react reveal.js react react-dom
  7. Use enqueued API calls for pre-initialization setup

    master

    The Reveal entrypoint allows you to call certain configuration and event methods before initialize() is actually executed. These calls are queued and automatically applied to the RevealApi instance once initialization completes.

    Supported methods for queuing include:

    • configure
    • on
    • off
    • addEventListener
    • removeEventListener
    • registerPlugin

    This ensures that event listeners and configurations are applied correctly even if they are defined before the DOM is fully ready or initialize() is called.

    import Reveal from './js/index.ts';
    
    // These calls are queued and executed after initialize()
    Reveal.on('ready', () => {
      console.log('Presentation is ready!');
    });
    
    Reveal.configure({ hash: true });
    
    // Finally, trigger the initialization
    Reveal.initialize();
  8. Configure Reveal via the Deck component

    master

    Pass a config object to the Deck component to set Reveal options. This object maps directly to the Reveal configuration object.

    Plugins should be passed to the plugins prop on Deck. Plugins are registered once during initialization and are not re-applied on subsequent renders.

    import { Deck, Slide } from '@revealjs/react';
    import 'reveal.js/reveal.css';
    import 'reveal.js/theme/black.css';
    import 'reveal.js/plugin/highlight/monokai.css';
    import RevealHighlight from 'reveal.js/plugin/highlight';
    
    export function Presentation() {
      return (
        <Deck
          config={{
            width: 1280,
            height: 720,
            hash: true,
            controls: true,
            progress: true,
            transition: 'slide',
          }}
          plugins={[RevealHighlight]}
        >
          <Slide>Configured deck</Slide>
        </Deck>
      );
    }
  9. Use Markdown for slide content

    master

    reveal.js supports Markdown for defining slide content. You can use standard Markdown syntax for headings, text, and special elements like images and mathematical equations.

    To create speaker notes, use the Note: prefix followed by your text. This content will only be visible in the speaker notes window during a presentation.

    ## External 1.1
    
    Content 1.1
    
    Note: This will only appear in the speaker notes window.
    
    ## External 3.3 (Image)
    
    ![External Image](https://static.slid.es/logo/v2/slides-symbol-512x512.png)
    
    ## External 3.4 (Math)
    
    $$ J(\theta_0,\theta_1) = \sum_{i=0} $$
  10. Use @revealjs/react components: Fragment, Code, Stack, and Markdown

    master

    The package provides several specialized components for common slide patterns:

    • Fragment: Reveals content incrementally. Use animation (e.g., fade-up) and as or asChild to control the rendered element.
    • Code: Renders syntax-highlighted blocks. Requires the reveal.js/plugin/highlight plugin.
    • Stack: Groups multiple Slide components into a vertical column.
    • Markdown: Renders Reveal-compatible markdown. It accepts string children, a markdown prop, or a src prop for external files.
    import { Deck, Slide, Stack, Markdown, Fragment, Code } from '@revealjs/react';
    import RevealHighlight from 'reveal.js/plugin/highlight';
    import 'reveal.js/plugin/highlight/monokai.css';
    
    export function Presentation() {
      return (
        <Deck plugins={[RevealHighlight]}>
          <Slide>
            <h2>Step by step</h2>
            <Fragment animation="fade-up" as="p">First point</Fragment>
            <Fragment animation="fade-up" asChild>
              <div>Second point</div>
            </Fragment>
            <Code language="javascript" lineNumbers>
              {`console.log('Hello, world!');`}
            </Code>
          </Slide>
    
          <Stack>
            <Slide>Vertical 1</Slide>
            <Slide>Vertical 2</Slide>
          </Stack>
    
          <Markdown
            separator="^\n---\n$"
            verticalSeparator="^\n--\n$"
            options={{ smartypants: true, animateLists: true }}
          >
            {`
              ## Markdown 1.1
              - First item <!-- .element: class="fragment" -->
              - Second item <!-- .element: class="fragment" -->
    
              --
    
              ## Markdown 1.2
    
              Notes:
              These become speaker notes.
    
              ---
    
              <!-- .slide: data-background="#111827" -->
              ## Markdown 2
            `}
          </Markdown>
        </Deck>
      );
    }