i using r studio create markdown document. tried:
jump [header 1](#anchor)
i set link when reader clicks it, can jump specific point on page.
let's point want them directed has header "##test".
here solution html documents using jquery:
--- title: "internal links" output: html_document --- # first section ## second section ### third section <script type="text/javascript"> // when document rendered... $(document).ready(function() { // ...select header elements... $('h1, h2, h3, h4, h5').each(function() { // ...and add id them corresponding 'titles' $(this).attr('id', $(this).html()); }); }); </script> <a href="#first section">go first section</a><br> <a href="#second section">go second section</a><br> <a href="#third section">go third section</a>
as comments point out, select headers, read out content (e.g. "first section") , add attribute id
value corresponding specific content each header. can link header using #header
(e.g. #first section
).
this of course extendable other elements wish put anchor on. if want link of chunks, add script document:
<script type="text/javascript"> $(document).ready(function() { $('pre.r').each(function(i) { $(this).attr('id', 'chunk_' + i); }); }); </script>
now can link chunks using <a href="chunk_i">my chunk</a>
i
goes 0, first chunk, n
, last chunk in document.
Comments
Post a Comment