使用R Markdown在HTML演示文稿内创建超链接

4

我希望我打的标签是正确的-我想使用R Studio中的Markdown创建一个HTML演示文稿。我想做的是创建超链接,当点击时可以跳转到指定页面,而不是像大多数演示文稿一样直线进行。例如:

---
title: "Presentation"
output: ioslides_presentation
---

## Slide 1

This is the first slide. I'd like to be able to insert hyperlinks to a different page within the slide. For example:

[Slide 2](hyperlink to slide 2) - clicking this would jump to slide 2

[Slide 3](hyperlink to slide 3) - clicking this would jump to slide 3

[Slide 4](hyperlink to slide 4) - clicking this would jump to slide 4

## Slide 2

Text for slide 2

## Slide 3

More text for slide 3

## Slide 4

Even more text for slide 4.  

这个可行吗?我尝试过搜索,但只找到了如何链接到外部网站(例如:[链接到谷歌](www.google.com))的方法。

2个回答

9

虽然结果并不完美,但是这是可能的:

[Slide 4](#4)

ioslides默认在新窗口中打开链接,这样链接在RStudio预览中将无法使用,并会在运行时创建新的浏览器标签页。

如果您不关心markdown纯度,那么使用一些HTML和JavaScript将更加容易:

<a href="javascript:slidedeck.loadSlide(4)">Slide 4</a>

谢谢,我已经让它工作了,但我希望将它全部保留在同一个选项卡中。我会继续调试并看看我能找出什么。 - GregRousell
我忘记了Pandoc不会剥离Javascript URIs - 请尝试更新的答案 :-) - Jonathan
最初,这对我没有起作用(至少在默认的Firefox和Edge浏览器中)。它需要添加参数:target="_self"。另请参阅:https://dev59.com/a1cP5IYBdhLWcg3wFmkw - user3283722

0

R Markdown 生成的幻灯片可以通过标题进行 href,这应该是有效的:

## Slide 1

This is the first slide. I'd like to be able to insert hyperlinks to
a different page within the slide. For example:

[Slide 2](#/my-second-slide) - clicking this would jump to slide 2

[Slide 3](#/my-third-slide) - clicking this would jump to slide 3

## My second slide

Text for slide 2

## My third slide

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