ids theme: automatic chapter numbering, ported from gdoc2reveal
Chapter headings (#) are numbered automatically when the presentation is
opened: "1. Introduction", "2. Methods", and so on. References, appendix
and thank-you chapters keep their bare titles and are not counted.
Manually typed leading numbers ("# 2. Methods") are stripped before
renumbering, so decks migrated from the old Google Docs pipeline and
repeated numbering runs stay stable.
The menu plugin and the transcript view show the numbers, too; the
Overview slide's table of contents prepends them as orange
.ids-toc-number spans flush with the slide heading, with the theme's
drawn list markers suppressed for the top-level entries (sub-headings
keep their bullets). Decks rendered with slide_level: 1 are left
unnumbered -- there, headings denote slides, not chapters.
Bump version to 0.9.1.9010.
Change-Id: I233086e039aee0da156cfaaebe04d05f3ad851ce
diff --git a/DESCRIPTION b/DESCRIPTION
index c4d244c..a779fe2 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,7 +1,7 @@
Type: Package
Package: revealjs.ids
Title: R Markdown Format for 'reveal.js' Presentations -- IDS Mannheim Corporate Design Theme Edition
-Version: 0.9.1.9009
+Version: 0.9.1.9010
Authors@R: c(
person("Marc", "Kupietz", , "kupietz@ids-mannheim.de", role = c("aut", "cre")),
person("Christophe", "Dervieux", , "cderv@posit.co", role = "aut"),
diff --git a/NEWS.md b/NEWS.md
index c2a1479..8ea6408 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,4 +1,6 @@
-# revealjs.ids (development version)
+# revealjs.ids 0.9.1.9010
+
+- Automatic chapter numbering (ported from the old Google Docs slide workflow): `#` chapter headings get a sequential "1. ", "2. " ... prefix when the presentation is opened. References, appendix and thank-you chapters keep their bare titles and are not counted; manually typed leading numbers (`# 2. Methods`) are stripped before renumbering, so decks migrated from the old pipeline and repeated numbering runs stay stable. The menu plugin and the transcript view show the numbers, too, and the Overview slide's table of contents uses them as its ordered list's enumeration (entry titles are stripped back to their bare form). Decks with `slide_level: 1` (one `#` heading per slide) are left unnumbered.
- Title slide branding (ported from posterdown.ids): three new optional yaml entries -- `website` places a linked QR code (generated with the qrcode package) in the top left of the title slide; `partner_logo` shows a second institution's logo next to the IDS logo in the top right of every slide (for talks by authors from two institutions); `funder_logo` puts a funder logo in the bottom left of the title slide, opposite the Leibniz Gemeinschaft membership logo. Local logo files are embedded as data URIs, so they need not be shipped; a linked QR code anywhere on a slide can be produced with the new `qrlink()` function in inline R code. The navigation chrome (arrows, slide number, menu button) is now hidden on the title slide.
diff --git a/R/revealjs_presentation.R b/R/revealjs_presentation.R
index 05c8131..047bda3 100644
--- a/R/revealjs_presentation.R
+++ b/R/revealjs_presentation.R
@@ -94,17 +94,36 @@
#' The function [slide_timing()] computes these totals directly from an
#' `.Rmd` source file without rendering it.
#'
+#' ## Chapter numbering
+#'
+#' Like in the old Google Docs slide workflow, chapter headings (`#`) are
+#' numbered automatically: the first chapter becomes "1. Introduction", the
+#' second "2. Methods", and so on. References, appendix and thank-you
+#' chapters (References/Literatur/Referenzen/Publikationen/
+#' Herausgeberschaften/Appendix/Anhang, and headings containing
+#' "Thank you"/"Vielen Dank") keep their bare titles and are not counted.
+#' Manually typed leading numbers (`# 2. Methods`) are stripped before
+#' renumbering, so decks migrated from the old pipeline and repeated
+#' numbering runs stay stable. The numbers are added when the presentation
+#' is opened: the menu plugin and the transcript view show them, too, and
+#' the overview slide's table of contents uses them as its ordered list's
+#' enumeration. Decks rendered with `slide_level = 1` (one `#` heading per
+#' slide) are left unnumbered -- there, headings denote slides, not
+#' chapters.
+#'
#' ## Overview slides
#'
#' Like in the original Google Docs slide workflow, a slide titled
#' "Overview" or "Überblick" is automatically turned into a table of
#' contents: its body content is replaced at presentation time with a
-#' clickable list of all `#` chapter headings. Adding
+#' clickable, ordered list of all `#` chapter headings, whose enumeration
+#' repeats the chapter numbers. Adding
#' `{data-overview-subheadings=true}` to the heading also includes the
#' `##` sub-headings below their chapters, laid out in two columns.
-#' References and appendix chapters (References/Literatur/
-#' Literaturverzeichnis/Appendix/Anhang) are left out, together with
-#' their sub-slides.
+#' References, appendix and thank-you chapters (References/Literatur/
+#' Literaturverzeichnis/Referenzen/Publikationen/Herausgeberschaften/
+#' Appendix/Anhang, and headings containing "Thank you"/"Vielen Dank") are
+#' left out, together with their sub-slides.
#'
#' ### Search
#'
diff --git a/README.Rmd b/README.Rmd
index f3eae50..a4b6e88 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -160,7 +160,7 @@
## Overview Slides
-Like in the old Google-Docs-based slide workflow, a slide titled "Overview" or "Überblick" is automatically turned into a table of contents: its body content is replaced with a list of all `#` chapter headings, and each entry links to the corresponding slide.
+Like in the old Google-Docs-based slide workflow, a slide titled "Overview" or "Überblick" is automatically turned into a table of contents: its body content is replaced with an ordered list of all `#` chapter headings, whose enumeration repeats the chapter numbers, and each entry links to the corresponding slide.
``` markdown
## Overview
@@ -176,6 +176,12 @@
The TOC is generated when the presentation is opened, so it always reflects the deck it is part of. Slides without a heading and the title slide are left out.
+## Chapter Numbering
+
+Like in the old Google-Docs-based slide workflow, `#` chapter headings are numbered automatically when the presentation is opened: the first chapter becomes "1. Introduction", the second "2. Methods", and so on. References, appendix and thank-you chapters (References/Literatur/Referenzen/Publikationen/Herausgeberschaften/Appendix/Anhang, and headings containing "Thank you"/"Vielen Dank") keep their bare titles and are not counted. Manually typed leading numbers (`# 2. Methods`) are stripped before renumbering, so the numbering also comes out right in decks migrated from the old pipeline. Since the numbers are added to the headings themselves, they show up everywhere the headings do: the menu plugin and the transcript view, and on the overview slide they become the enumeration of the table of contents.
+
+Decks with `slide_level: 1` (one `#` heading per slide) are left unnumbered -- there, headings denote slides, not chapters.
+
## Incremental Bullets
You can render bullets incrementally by adding the `incremental` option:
diff --git a/README.md b/README.md
index ae1cb90..5a1bd91 100644
--- a/README.md
+++ b/README.md
@@ -219,8 +219,9 @@
Like in the old Google-Docs-based slide workflow, a slide titled
"Overview" or "Überblick" is automatically turned into a table of
-contents: its body content is replaced with a list of all `#` chapter
-headings, and each entry links to the corresponding slide.
+contents: its body content is replaced with an ordered list of all `#`
+chapter headings, whose enumeration repeats the chapter numbers, and
+each entry links to the corresponding slide.
``` markdown
## Overview
@@ -230,9 +231,10 @@
To also include the `##` sub-headings below their chapters, add
`{data-overview-subheadings=true}` to the heading; the list is then
-laid out in two columns. References and appendix chapters
-(References/Literatur/Literaturverzeichnis/Appendix/Anhang) are left
-out, together with their sub-slides.
+laid out in two columns. References, appendix and thank-you chapters
+(References/Literatur/Literaturverzeichnis/Referenzen/Publikationen/
+Herausgeberschaften/Appendix/Anhang, and headings containing "Thank
+you"/"Vielen Dank") are left out, together with their sub-slides.
``` markdown
## Overview {data-overview-subheadings=true}
@@ -242,6 +244,25 @@
reflects the deck it is part of. Slides without a heading and the
title slide are left out.
+## Chapter Numbering
+
+Like in the old Google-Docs-based slide workflow, `#` chapter headings
+are numbered automatically when the presentation is opened: the first
+chapter becomes "1. Introduction", the second "2. Methods", and so on.
+References, appendix and thank-you chapters
+(References/Literatur/Referenzen/Publikationen/Herausgeberschaften/
+Appendix/Anhang, and headings containing "Thank you"/"Vielen Dank")
+keep their bare titles and are not counted. Manually typed leading
+numbers (`# 2. Methods`) are stripped before renumbering, so the
+numbering also comes out right in decks migrated from the old
+pipeline. Since the numbers are added to the headings themselves, they
+show up everywhere the headings do: the menu plugin and the transcript
+view, and on the overview slide they become the enumeration of the
+table of contents.
+
+Decks with `slide_level: 1` (one `#` heading per slide) are left
+unnumbered -- there, headings denote slides, not chapters.
+
## Incremental Bullets
You can render bullets incrementally by adding the `incremental` option:
diff --git a/inst/reveal.js-5.2.1/css/theme/source/ids.scss b/inst/reveal.js-5.2.1/css/theme/source/ids.scss
index e0a7634..e833b8f 100644
--- a/inst/reveal.js-5.2.1/css/theme/source/ids.scss
+++ b/inst/reveal.js-5.2.1/css/theme/source/ids.scss
@@ -202,11 +202,17 @@
// Ordered lists: the CSS list-item counter honours the HTML start/value
// attributes, so pandoc's `start`/`value` lists keep their numbers. Numbers
-// are right-aligned into the indent, ending just before the item text.
+// are anchored with their right edge $idsNumberGap away from the item text
+// (a shrink-to-fit box; anchoring from the right instead of a fixed-width,
+// right-aligned box, because over-wide numbers would otherwise overflow
+// INTO the text). Longer numbers like "10." grow to the left.
+$idsNumberGap: 0.3em;
+
.reveal .slides section:not(.title-frame) ol > li::before {
content: counter(list-item, decimal) "." !important;
- width: calc(#{$idsListIndent} - 0.12em) !important;
- text-align: right !important;
+ left: auto !important;
+ right: 100% !important;
+ margin-right: $idsNumberGap !important;
}
// Checkbox (pandoc task) lists keep their checkboxes, no markers on top.
@@ -1124,9 +1130,23 @@
/*********************************************
* OVERVIEW / TOC SLIDES
*********************************************/
-/* Entries stay at the normal slide body size and keep the theme's link
- colour, so they read as the navigation links they are. Only the denser
- two-column variant with sub-headings is scaled down. */
+/* The auto-generated TOC lists the chapters with their numbers as
+ .ids-toc-number spans in the marker colour, prepended to the entry
+ titles: the enumeration therefore starts flush with the slide heading
+ (the drawn ol/ul markers are suppressed for the top-level entries;
+ sub-headings below their chapters keep their bullets). Entries stay at
+ the normal slide body size and keep the theme's link colour, so they
+ read as the navigation links they are. Only the denser two-column
+ variant with sub-headings is scaled down. */
+.reveal .slides section:not(.title-frame) .ids-overview-toc {
+ padding-left: 0 !important;
+}
+.reveal .slides section:not(.title-frame) .ids-overview-toc > li::before {
+ content: none !important;
+}
+.reveal .ids-overview-toc .ids-toc-number {
+ color: var(--r-list-bullet-color);
+}
.reveal .ids-overview-toc {
list-style: none;
margin: 0.2em 0 0 0;
diff --git a/inst/reveal.js-5.2.1/dist/theme/ids.css b/inst/reveal.js-5.2.1/dist/theme/ids.css
index 43fe710..dd54e86 100644
--- a/inst/reveal.js-5.2.1/dist/theme/ids.css
+++ b/inst/reveal.js-5.2.1/dist/theme/ids.css
@@ -415,8 +415,9 @@
.reveal .slides section:not(.title-frame) ol > li::before {
content: counter(list-item, decimal) "." !important;
- width: calc(0.65em - 0.12em) !important;
- text-align: right !important;
+ left: auto !important;
+ right: 100% !important;
+ margin-right: 0.3em !important;
}
.reveal .slides section:not(.title-frame) ul.task-list li::before {
@@ -1146,9 +1147,26 @@
/*********************************************
* OVERVIEW / TOC SLIDES
*********************************************/
-/* Entries stay at the normal slide body size and keep the theme's link
- colour, so they read as the navigation links they are. Only the denser
- two-column variant with sub-headings is scaled down. */
+/* The auto-generated TOC lists the chapters with their numbers as
+ .ids-toc-number spans in the marker colour, prepended to the entry
+ titles: the enumeration therefore starts flush with the slide heading
+ (the drawn ol/ul markers are suppressed for the top-level entries;
+ sub-headings below their chapters keep their bullets). Entries stay at
+ the normal slide body size and keep the theme's link colour, so they
+ read as the navigation links they are. Only the denser two-column
+ variant with sub-headings is scaled down. */
+.reveal .slides section:not(.title-frame) .ids-overview-toc {
+ padding-left: 0 !important;
+}
+
+.reveal .slides section:not(.title-frame) .ids-overview-toc > li::before {
+ content: none !important;
+}
+
+.reveal .ids-overview-toc .ids-toc-number {
+ color: var(--r-list-bullet-color);
+}
+
.reveal .ids-overview-toc {
list-style: none;
margin: 0.2em 0 0 0;
diff --git a/inst/rmarkdown/templates/revealjs_presentation/resources/default.html b/inst/rmarkdown/templates/revealjs_presentation/resources/default.html
index cf56f8e..45b55e4 100644
--- a/inst/rmarkdown/templates/revealjs_presentation/resources/default.html
+++ b/inst/rmarkdown/templates/revealjs_presentation/resources/default.html
@@ -1013,16 +1013,101 @@
</script>
$endif$
<script>
+ // Chapter classification shared by the numbering and overview TOC scripts
+ // below (ported from the gdoc2reveal workflow): chapters are the level-1
+ // (pandoc "title-slide") sections of a deck. References, appendix and
+ // thank-you chapters are exempt from numbering and left out of the
+ // overview TOC.
+ window.idsChapters = (function () {
+ var EXCLUDED = ['references', 'literatur', 'literaturverzeichnis',
+ 'referenzen', 'publikationen', 'herausgeberschaften', 'appendix',
+ 'anhang'];
+ var THANK_YOU = /thank[\s\S]*you|vielen[\s\S]*dank/i;
+ // like the old pipeline: drop a leading "12.", "3)" or "-" plus
+ // whitespace, but leave headings like "3D printing" alone
+ var STRIP_NUMBER = /^\s*[-\d]+\s*(?:[.)]|\s)\s*/;
+
+ function isExcluded(title) {
+ var t = title.trim().toLowerCase();
+ return EXCLUDED.indexOf(t) !== -1 || THANK_YOU.test(t);
+ }
+
+ function isChapterSlide(slide) {
+ return !slide.classList.contains('title-frame') &&
+ slide.classList.contains('title-slide') &&
+ !!slide.querySelector('h1');
+ }
+
+ return {
+ isExcluded: isExcluded,
+ isChapterSlide: isChapterSlide,
+ stripNumber: function (title) { return title.replace(STRIP_NUMBER, ''); }
+ };
+ })();
+</script>
+<script>
+ // Automatic chapter numbering (ported from the gdoc2reveal workflow):
+ // chapter headings get a sequential "1. ", "2. " ... prefix, except
+ // references, appendix and thank-you chapters, which keep their bare
+ // titles and are not counted. Manually typed leading numbers are stripped
+ // first, so rendering twice or renumbering an already numbered deck stays
+ // stable. Runs before the overview TOC builder below: the menu plugin and
+ // the transcript view show the numbers, while the overview TOC strips
+ // them again and numbers its ordered list entries instead, like the old
+ // Google Docs workflow did.
+ (function () {
+ function firstTextNode(el) {
+ var n = el.firstChild;
+ while (n && n.nodeType !== Node.TEXT_NODE) n = n.nextSibling;
+ return n;
+ }
+
+ function numberChapters() {
+ if (typeof Reveal === 'undefined' || !Reveal.isReady()) return;
+ var n = 0;
+ Reveal.getSlides().forEach(function (slide) {
+ if (!window.idsChapters.isChapterSlide(slide)) return;
+ var h = slide.querySelector('h1');
+ if (window.idsChapters.isExcluded(h.textContent)) return;
+ n += 1;
+ slide.dataset.chapterNumber = n;
+ var t = firstTextNode(h);
+ if (!t) {
+ t = document.createTextNode('');
+ h.insertBefore(t, h.firstChild);
+ }
+ var label = window.idsChapters.stripNumber(t.nodeValue);
+ if (t === h.firstChild) {
+ t.nodeValue = n + '. ' + label;
+ } else {
+ // the heading starts with an element (e.g. <em>): put the number
+ // in front of it instead of into the first text node
+ t.nodeValue = label;
+ h.insertBefore(document.createTextNode(n + '. '), h.firstChild);
+ }
+ });
+ }
+
+ if (typeof Reveal !== 'undefined') {
+ if (Reveal.isReady()) numberChapters();
+ else Reveal.addEventListener('ready', numberChapters);
+ }
+ })();
+</script>
+<script>
// Slides whose (only) heading is "Overview" or "Überblick" are
// automatically populated with a table of contents of the deck's h1 slide
// headings, replacing whatever body content the slide had (ported from the
// Google Docs slide workflow). By adding {data-overview-subheadings=true}
// to the heading, h2 sub-headings are included below their chapters and
// the list is laid out in two columns. References and appendix chapters
- // (English and German) are left out. Styling in the ids theme.
+ // (English and German) are left out. The chapter numbers (set on the
+ // headings by the numbering script above) are prepended to the entry
+ // titles as .ids-toc-number spans, so the enumeration starts flush with
+ // the slide heading; the ids theme styles the spans in the marker colour
+ // and suppresses its own drawn list markers for the top-level entries.
(function () {
var TITLES = ['overview', 'überblick'];
- var EXCLUDED = ['references', 'literatur', 'literaturverzeichnis', 'appendix', 'anhang'];
function isOverviewSlide(slide) {
var h = slide.querySelector('h1,h2');
@@ -1041,7 +1126,7 @@
var includeSub = (heading.getAttribute('data-overview-subheadings') || '')
.toLowerCase() !== 'false'
&& heading.hasAttribute('data-overview-subheadings');
- var list = document.createElement('ul');
+ var list = document.createElement('ol');
list.className = 'ids-overview-toc';
if (includeSub) list.classList.add('with-subheadings');
var subList = null;
@@ -1051,12 +1136,22 @@
var h = slide.querySelector('h1,h2');
if (!h) return;
if (h.tagName === 'H1') {
- excluded = EXCLUDED.indexOf(h.textContent.trim().toLowerCase()) !== -1;
+ excluded = window.idsChapters.isExcluded(h.textContent);
}
if (excluded || (h.tagName !== 'H1' && !includeSub)) return;
var link = document.createElement('a');
link.href = '#/' + slide.id;
- link.textContent = h.textContent;
+ if (h.tagName === 'H1' && slide.dataset.chapterNumber) {
+ var number = document.createElement('span');
+ number.className = 'ids-toc-number';
+ number.textContent = slide.dataset.chapterNumber + '. ';
+ link.appendChild(number);
+ link.appendChild(document.createTextNode(
+ window.idsChapters.stripNumber(h.textContent)
+ ));
+ } else {
+ link.textContent = h.textContent;
+ }
var item = document.createElement('li');
item.appendChild(link);
if (h.tagName === 'H1') {
diff --git a/man/revealjs_presentation.Rd b/man/revealjs_presentation.Rd
index 9735960..ce1e0c6 100644
--- a/man/revealjs_presentation.Rd
+++ b/man/revealjs_presentation.Rd
@@ -249,17 +249,37 @@
\code{.Rmd} source file without rendering it.
}
+\subsection{Chapter numbering}{
+
+Like in the old Google Docs slide workflow, chapter headings (\verb{#}) are
+numbered automatically: the first chapter becomes "1. Introduction", the
+second "2. Methods", and so on. References, appendix and thank-you
+chapters (References/Literatur/Referenzen/Publikationen/
+Herausgeberschaften/Appendix/Anhang, and headings containing
+"Thank you"/"Vielen Dank") keep their bare titles and are not counted.
+Manually typed leading numbers (\verb{# 2. Methods}) are stripped before
+renumbering, so decks migrated from the old pipeline and repeated
+numbering runs stay stable. The numbers are added when the presentation
+is opened: the menu plugin and the transcript view show them, too, and
+the overview slide's table of contents uses them as its ordered list's
+enumeration. Decks rendered with \code{slide_level = 1} (one \verb{#} heading per
+slide) are left unnumbered -- there, headings denote slides, not
+chapters.
+}
+
\subsection{Overview slides}{
Like in the original Google Docs slide workflow, a slide titled
"Overview" or "Überblick" is automatically turned into a table of
contents: its body content is replaced at presentation time with a
-clickable list of all \verb{#} chapter headings. Adding
+clickable, ordered list of all \verb{#} chapter headings, whose enumeration
+repeats the chapter numbers. Adding
\code{{data-overview-subheadings=true}} to the heading also includes the
\verb{##} sub-headings below their chapters, laid out in two columns.
-References and appendix chapters (References/Literatur/
-Literaturverzeichnis/Appendix/Anhang) are left out, together with
-their sub-slides.
+References, appendix and thank-you chapters (References/Literatur/
+Literaturverzeichnis/Referenzen/Publikationen/Herausgeberschaften/
+Appendix/Anhang, and headings containing "Thank you"/"Vielen Dank") are
+left out, together with their sub-slides.
\subsection{Search}{
Activated by default: pressing \code{CTRL + SHIFT + F} shows a search box.