使用pandoc在reveal.js中制作一级和二级幻灯片

22
我正在使用markdown生成一个幻灯片,并将其转换为html格式(使用pandoc命令:pandoc -s -S -t revealjs test.md -o test.html)。
reveal.js框架允许2D设置:在垂直方向上分组幻灯片子集,在水平方向上分组幻灯片子集。在markdown中,可以通过以下方式实现:
# Head1

## Below 1

text below 1

## Below 2

text below 2

# Head 2

这将产生预期的输出。结果有四个幻灯片,排列如下:
[  Head 1 ] [ Head 2 ]
[ Below 1 ]
[ Below 2 ]

然而,我想在“标题1”幻灯片中添加一些进一步的内容。这在reveal.js中是可能的,但以下markdown无法被pandoc正确处理:
# Head1

Head text 1

## Below 1

text below 1

## Below 2

text below 2

# Head 2

因为幻灯片级别变成了1而不是2,所以我只得到了两张幻灯片(每个一级标题有一张)。我可以使用 pandoc 的选项强制将幻灯片级别设为2:
pandoc -s -S -t revealjs test.md -o test.html --slide-level 2

但是接下来我又回到了最初的排列方式——失去了任何直接位于“标题1”下方的内容。

有什么想法吗?


我在使用 pandoc -t revealjs -s -o index.html index.md 时遇到了同样的问题。真的找不到解决方法 :( - Beerend Lauwers
4个回答

20

自从Pandoc 2.7(2019年3月)发布以来:

幻灯片格式的行为发生了变化:标题下级别小于幻灯片级别的内容不再被忽略,而是包含在标题幻灯片中(适用于HTML幻灯片),或者在标题幻灯片后的幻灯片中(适用于beamer)。此变化使得每个堆栈顶部幻灯片中的2D reveal.js幻灯片具有内容(#4317#5237)。

给定此输入test.md文件:

# Head1

Head text 1

## Below 1

text below 1

## Below 2

text below 2

# Head 2

运行中:

pandoc -s -t revealjs test.md -o test.html --slide-level 2

这将生成一个reveal.js幻灯片演示,其中第一张幻灯片包含:

<h1>Head1</h1>
<p>Head text 1</p>

在Pandoc 2.7之前,如果您想将幻灯片嵌套到第二级,则不能将内容放置在一级标题下。这个限制是有意设计的。根据开发人员John MacFarlane在2015年6月所说:

Pandoc有一种将内容划分为幻灯片的方法(在用户指南中描述),适用于所有幻灯片格式,因此您可以使用相同的源代码来制作reveal.js和beamer。这就是当前系统的动机,尽管我也希望有更好的方法,只要它能与所有格式统一工作。


2

更新

pandoc 2.7

幻灯片显示格式行为更改:标题级别低于幻灯片级别的内容不再被忽略,但包含在标题幻灯片中(用于HTML幻灯片),或在标题幻灯片后的幻灯片中(用于beamer)。 这个变化使得顶部幻灯片上有2D reveal.js幻灯片积木的内容 (#4317, #5237).

(已添加强调). 我还没有测试过。

以前的答案

这对我来说可以使用当前的pandoc版本

# That presentation

## dummy slide

<!--javascript to remove dummy slide-->
<script>
document.getElementById("dummy-slide").remove();
</script>

<!--end dummy slide-->
</section>

<section>
<section class="titleslide slide level1">
<h1>Head 1<h1>
Head text 1

<!-- dummy-slide creates it's section end tag -->
<!-- </section> -->

## Below 1

text below 1

## Below 2

text below 2

</section>

<!-- need extra end tag before next section -->
</section>

<section class="titleslide slide level1">
<h1>Head 2<h1>
Head text 1
</section>

# Head 3

这种方法有些违背了Markdown的思想,并且可能无法与一些先前或后续版本的Pandoc兼容。然而在使用Rmarkdown时,我仍然觉得它很有用。上述内容是通过以下方式生成的:

---
title: "That presentation"
output: 
  revealjs::revealjs_presentation:
    keep_md: TRUE
---

## dummy slide

<!--javascript to remove dummy slide-->
<script>
document.getElementById("dummy-slide").remove();
</script>

<!--end dummy slide-->
</section>

<section>
<section class="titleslide slide level1">
<h1>Head 1<h1>
Head text 1

<!-- dummy-slide creates it's section end tag -->
<!-- </section> -->

## Below 1

text below 1

## Below 2

text below 2

</section>

<!-- need extra end tag before next section -->
</section>

<section class="titleslide slide level1">
<h1>Head 2<h1>
Head text 1
</section>

# Head 3

0
如果我理解你的意思正确的话,下面的代码应该可以解决问题:
# Head1

---

Head text 1

## Below 1

text below 1

## Below 2

text below 2

# Head 2

使用您提到的第一条命令进行编译:

pandoc -s -S -t revealjs test.md -o test.html

3
不,这会将“标题1”的文本放在自己的幻灯片中。OP希望“标题1”成为“标题1”幻灯片的一部分。 - approxiblue

-1
这里提供了一个解决方法(https://github.com/rstudio/revealjs/issues/40),建议按照以下步骤操作(对我来说有效):
---
title    : Title
date     : Dec 22, 2016
output   : 
    revealjs::revealjs_presentation
---

<section class="titleslide level1">
<h1>TOP SLIDE</h1>

Some blabla

## SUBSLIDE

Some sub-blabla
</section>

# Next section slide

## Next subslide

Text as per standard layout

1
对我来说,这个解决方法只适用于第一部分... :-( 很遗憾,这违背了使用reveal.js 2D演示的目的... - kiero

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接