support speaker notes and timing comments on the title slide
Pandoc puts content written before the first heading into an otherwise
empty phantom slide right after the title slide. When such a slide
consists of nothing but ::: notes blocks, timing comments, and
whitespace, it is now merged into the title slide: the title gets the
data-timing attribute and the notes, the phantom slide disappears, and
slide_timing() reports the title time as "(title)".
Change-Id: I984e924c467c4e15905b97c128c380887132f09d
diff --git a/tests/testthat/test-slide_timing.R b/tests/testthat/test-slide_timing.R
index edcce26..48bc3d1 100644
--- a/tests/testthat/test-slide_timing.R
+++ b/tests/testthat/test-slide_timing.R
@@ -144,6 +144,74 @@
expect_true(any(grepl("totalTime:\\s*120", html)))
})
+test_that("title slide notes and timing are merged into the title section", {
+ lines <- c(
+ '<section class="title-frame" id="title-slide">',
+ "<h1 class=\"title\">Title</h1>",
+ "</section>",
+ "<section class=\"slide level2\">",
+ "<!-- JD 00:30 -->",
+ "<aside class=\"notes\">",
+ "<p>Welcome</p>",
+ "</aside>",
+ "</section>",
+ "<section id=\"slide-a\" class=\"slide level2\">",
+ "<!-- MK 01:00 -->",
+ "</section>"
+ )
+ merged <- merge_title_slide_notes(lines)
+ # phantom slide (6 lines) removed, its 4 content lines moved into the title
+ expect_length(merged, length(lines) - 2)
+ expect_identical(merged[1], lines[1])
+ expect_match(paste(merged[1:5], collapse = "\n"), "Welcome")
+ expect_match(paste(merged[1:5], collapse = "\n"), "JD 00:30")
+ # only the real Slide A section remains
+ expect_equal(sum(grepl('class="slide level2"', merged)), 1)
+
+ # a phantom slide with real content is left alone
+ with_content <- lines
+ with_content[6] <- "<p>Visible intro content</p>"
+ expect_identical(merge_title_slide_notes(with_content), with_content)
+
+ # no title slide: nothing to merge
+ no_title <- lines[-1]
+ expect_identical(merge_title_slide_notes(no_title), no_title)
+})
+
+test_that("rendered title slides carry notes and data-timing", {
+ skip_if_not_pandoc()
+ skip_if_not_installed("xml2")
+ rmd <- local_temp_rmd_file(
+ "---",
+ "title: Timing test",
+ "output: revealjs.ids::revealjs_presentation",
+ "---",
+ "",
+ "::: notes",
+ "Welcome note",
+ ":::",
+ "",
+ "<!-- 00:30 -->",
+ "",
+ "## Slide A",
+ "",
+ "Content A"
+ )
+ html <- .render_and_read(rmd)
+ title <- xml2::xml_find_first(html, "//section[@id='title-slide']")
+ expect_equal(xml2::xml_attr(title, "data-timing"), "30")
+ expect_equal(
+ xml2::xml_text(xml2::xml_find_first(title, "./aside[@class='notes']"), trim = TRUE),
+ "Welcome note"
+ )
+ # no phantom slide between title and first content slide
+ sections <- xml2::xml_find_all(html, "//section[@class]")
+ expect_equal(
+ xml2::xml_attr(sections[1:2], "id"),
+ c("title-slide", "slide-a")
+ )
+})
+
test_that("a user-supplied totalTime is respected", {
skip_if_not_pandoc()
rmd <- local_temp_rmd_file(