Joe*_*val 10 html rstudio knitr r-markdown
我正在使用R Studio创建降价文档.我试过了:
Jump to [Header 1](#anchor)
Run Code Online (Sandbox Code Playgroud)
我想设置一个链接,以便当读者点击它时,可以跳转到页面上的特定点.
让我们说我希望它们被指向的点有一个标题"## Test".
sco*_*coa 38
Pandoc支持标题的显式和隐式节引用; 请参阅pandoc手册.
## Test {#test},然后使用链接语法引用它:see [the relevant section](#test).## Test,仍然可以参考:See the section called [Test].这两种语法都应该允许您单击链接以转到锚点,并且应该以大多数输出格式工作.(仅用html和pdf测试).
---
output: pdf_document
---
## A section
blah blah
## A second section with a custom identifier {#custom}
blah blah
## Links
You can use implicit references to refer to sections
you have not explicitly named, like this:
see [A section].
You can use links to refere to sections with explicit
references, like this: see [the second section](#custom).
Run Code Online (Sandbox Code Playgroud)
以下是使用 jQuery 的 HTML 文档解决方案:
---
title: "Internal Links"
output: html_document
---
# First Section
## Second Section
### Third Section
<script type="text/javascript">
// When the document is fully rendered...
$(document).ready(function() {
// ...select all header elements...
$('h1, h2, h3, h4, h5').each(function() {
// ...and add an id to them corresponding to their 'titles'
$(this).attr('id', $(this).html());
});
});
</script>
<a href="#First Section">Go to first section</a><br>
<a href="#Second Section">Go to second section</a><br>
<a href="#Third Section">Go to third section</a>
Run Code Online (Sandbox Code Playgroud)
正如评论所指出的,我们只需选择所有标头,读出其内容(例如“第一部分”),然后将id具有与特定内容相对应的值的属性添加到每个标头。#HEADER现在您可以使用(例如)链接到任何标头#First Section。
这当然可以扩展到您希望锚定的所有其他元素。因此,如果您想链接到任何块,只需将此脚本添加到您的文档中即可:
<script type="text/javascript">
$(document).ready(function() {
$('pre.r').each(function(i) {
$(this).attr('id', 'Chunk_' + i);
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
现在,您可以使用从 0(第一个块)到(文档中的最后一个块)的<a href="Chunk_i">My Chunk</a>where来链接到块。iN
| 归档时间: |
|
| 查看次数: |
7354 次 |
| 最近记录: |