Revealjs 是一个只做 Web 幻灯片的工具。本文分为两部分,一部分为 vscode-reveal,已经足够日常使用。另一部分原生 Revealjs,可以进一步阅读。
vscode-reveal
VSCode extension evilz.vscode-reveal简化了 Revealjs(说简化可能不准确,但是从 vscode-reveal 了解起来轻松很多),只需要一个 md 文件就可以生成一个 slides。
See my revealjs-template for live demo/guide.
- VSCode Extension: https://github.com/evilz/vscode-reveal
Tips
- Slides can be nested inside of each other as
Vertical Slides. Use the Space key to navigate through all slides. - Press ESC to enter the slide overview.
- Alt + Click: Zoom in. Repeat to zoom back out.
- Press the S key to show speaker view. It includes a timer, preview of the upcoming slide as well as your speaker notes.
- Press . on your keyboard to pause the presentation.
- Press B or click on the pencil button to open and close your chalkboard.
- Click the left mouse button to write on the chalkboard
- Click the right mouse button to wipe the chalkboard
- Click the DEL key to clear the chalkboard, for MacOS, fn + del
- By pressing C or clicking the button you can start and stop the notes taking mode allowing you to write comments and notes directly on the slide.
- Click the left mouse button to write on the chalkboard
- Click the right mouse button to wipe the chalkboard
- Click the DEL key to clear the chalkboard, for MacOS, fn + del
- Press M to open or close the menu.
- CTRL + SHIFT + F handles finding a text string anywhere in the slides.
Revealjs
Installation
- Download the latest version of reveal.js from https://github.com/hakimel/reveal.js/releases
- Unzip and replace the example contents in index.html with your own
- Open index.html in a browser to view it
Folder Structure:
- css/ Core styles without which the project does not function
- js/ Like above but for JavaScript
- plugin/ Components that have been developed as extensions to reveal.js
- lib/ All other third party assets (JavaScript, CSS, fonts)
Instructions
Markup
Here’s a barebones example of a fully working reveal.js presentation:
1 | <html> |
The presentation markup hierarchy needs to be .reveal > .slides > section where the section represents one slide and can be repeated indefinitely. If you place multiple section elements inside of another section they will be shown as vertical slides. The first of the vertical slides is the “root” of the others (at the top), and will be included in the horizontal sequence. For example:
1 | <div class="reveal"> |
Markdown
It’s possible to write your slides using Markdown. To enable Markdown, add the data-markdown attribute to your <section> elements and wrap the contents in a <textarea data-template> like the example below. You’ll also need to add the plugin/markdown/marked.js and plugin/markdown/markdown.js scripts (in that order) to your HTML file.
This is based on data-markdown from Paul Irish modified to use marked to support GitHub Flavored Markdown. Sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks).
1 | <section data-markdown> |
External Markdown
You can write your content as a separate file and have reveal.js load it at runtime. Note the separator arguments which determine how slides are delimited in the external file: the data-separator attribute defines a regular expression for horizontal slides (defaults to ^\r?\n---\r?\n$, a newline-bounded horizontal rule) and data-separator-vertical defines vertical slides (disabled by default). The data-separator-notes attribute is a regular expression for specifying the beginning of the current slide’s speaker notes (defaults to notes?:, so it will match both “note:” and “notes:”). The data-charset attribute is optional and specifies which charset to use when loading the external file.
When used locally, this feature requires that reveal.js runs from a local web server. The following example customises all available options:
1 | <section |
Element Attributes
Special syntax (through HTML comments) is available for adding attributes to Markdown elements. This is useful for fragments, amongst other things.
1 | <section data-markdown> |
Slide Attributes
Special syntax (through HTML comments) is available for adding attributes to the slide <section> elements generated by your Markdown.
1 | <section data-markdown> |
Configuring marked
We use marked to parse Markdown. To customise marked’s rendering, you can pass in options when configuring Reveal:
1 | Reveal.initialize({ |
Configuration
At the end of your page you need to initialize reveal by running the following code. Note that all configuration values are optional and will default to the values specified below.
1 | Reveal.initialize({ |
The configuration can be updated after initialization using the configure method:
1 | // Turn autoSlide off |