Rmarkdown (html): local search for table of contents (toc) - html

I was wondering if Rmarkdown for html outputs has a function that can do a local search for the TOC only. I don't want to use the Ctrl+F function as I have got repeated words used as the section names and it would be much slower than just searching over the TOC.

The TOC is built using Tocify.js. It does not have any such feature, so don't expect anything in RMarkdown unless you cook one up using JQuery/Javascript.

Related

Markdown TOC with Special Characters?

I am trying to create a TOC for my Markdown blog.
The methods I am finding here... : Markdown to create pages and table of contents?
....do not work for me because I am naming all of my headers # _</>_ The Setup because I am using CSS on to style the "", giving each header a nice colored Icon next to it. If I simply use ```# The Setup ```` it works great.
This causes issues whenever I try to use [The Setup](#The-Setup).
I tried a few things like [The Setup](#_</>_-The-Setup) and other things, but I can not get it to work.
If someone can point me in the right direction I would greatly appreciate it. Also, if anyone has a better way of adding custom icons next to headers, I think that would be the better way to go about it.
As always, thanks in advance.
The general solution is to examine the rendered HTML output to see what the tool is converting the special characters to, in the HTML's element ID. Every tool could handle the conversion differently (it could convert special characters to -, _, or just remove special characters). Some examples:
<h1 id="_____the-setup">The Setup</h1>
<h1 id="-the-setup">The Setup</h1>
<h1 id="the-setup">The Setup</h1>
Once you have identified the exact id that the tool is using, then you use that value as the heading link in the markdown's table of contents. For example:
[The Setup](#_____the-setup)
Now, the tricky part is that not all Markdown tools will export the rendered HTML, including VS Code. The workaround for VS Code is:
Open the markdown preview mode (which renders to html internally).
Open the VS Code Developer Tools (Help > Toggle Developer Tools).
Use DevTools to inspect the element (in this case, the heading element for "The Setup").
I see that VS Code named the id as the-setup, so in the markdown's table of contents, I write [The Setup](#the-setup). Now the table of content hyperlink works in VS Code. Caveat: it might not work in other Markdown tools if they render a different HTML element ID!
Another shortcut now available in VS Code (1.70 July 2022), is that markdown can autocomplete the header ID. So you just type #, and it will list the valid IDs:

Why csv-table can not skip pages in sphinx-doc

I use sphinx to generate PDF files,but when I use csv-table to generate pdf,I found the generated csv-table could not skip pages automatically? How do I fix it?
You might want to try the Sphinx builder included with rinohtype, which offers a drop-in replacement for the LaTeX builder.
rinohtype will split your tables across pages. It can also automatically size table column widths, unlike the LaTeX builder. Another advantage is that rinohtype's PDF output can be styled more easily by means of CSS-like style sheets in case you need this.
(Full disclosure: I am the author of rinohtype)
I solved this problem by adding the class longtable
.. csv-table::
:file: path-to-csv-file
:class: longtable

How to incorporate html table in Rmarkdown

I used package 'sjPlot' to run some data analyses. For instant, function 'sjt.df' gives me a html table regarding simple description of variables. Then I created a Rmarkdown (see below). But when I clicked knit HTML/pdf, the result of the html table did not incorporate into the Rmarkdown. Rather, it popped up in my browser. How can I deal with that?
{r}
library(sjPlot)
data(iris)
sjt.df(iris)
See my tutorial basics of sjt-functions, section Knitr integration of HTML tables.
If you just want to have the table, use 'r sjt.df(iris, no.output=TRUE)$knitr' - (note that the ' have to be `).
The no.output=TRUE ensures that the table is not displayed in the viewer pane or browser, and the $knitr parameter contains the HTML-snippet that will be incorporated in RMarkdown.
If you also want to display the R-code, use
```{r eval=FALSE}
sjt.df(iris)
```
However, I guess that these tables are not converted well to PDF, only to HTML.

Jekyll/Octopress text modification. Filter, generator...converter?

I am building an octopress blog. In that blog, a number of entries have footnotes. The markdown files currently denote a footnote like so:
"This is the main text <footnote>and this is the footnote</footnote> where
we speak of main-text things"
What I want to do is extract the footnotes from the body text and then have access to both the main text AND the footnotes as variables in the layout.
I've made some progress with this by creating a filter but it doesn't work very well because filters always output directly on return and I need to format the footnotes.
Would a generator be more appropriate? A converter? Should I not be using liquid tags at all in this case?
Filters make the most sense to me. Is there a way to get the return value of a filter without it printing to the screen? I currently use this:
{{ content | footnotes }}
But that just dumps the array as one big, unformatted array. If it isn't blindingly obvious already, I'm just getting started with Liquid and I'm a little confused.
Depending on your markdown parser you could just write the footnotes normally in the markdown. This is what I'm using on my blog. This is my config in the _config.yml file:
markdown: rdiscount
rdiscount:
extensions:
- autolink
- footnotes
- smart
Then I just use footnotes by using [^1] to specify the footnote and
[^1]: My footnote
To show it at the bottom of the screen.
Or are you trying to show footnotes at some other part of the screen and not at the bottom of the post?

How to define a TOC in HTML for kindlegen to recognize

I convert a book which is written in DocBook into a single page HTML. The HTML contains a TOC:
<div class="toc">
<dl>
<dt><span class="preface">Preface</span></dt>
<dt><span class="chapter"><a href="#installation-und-versionsauswahl">1. Version Selection and
Installation</a></span></dt>
[...]
I'd like to use kindlegen to convert the HTML into a file I can use with a Kindle. That works without a problem. BUT the TOC is not recognized as a TOC. The Kindle user can't access the TOC directly with the TOC button.
What do I have to change that kindlegen recognize the TOC in my HTML file?
I'd recommend reading the official Kindle publishing guidlines from Amazon.
AFAIK kindlegen can't do that, you need a proper NCX file or an OPF with properly set TOC setting.
See also this short tutorial.
In case useful, I knocked up a quick PHP script to generate very basic NCX and OPF files to support the TOC without having to break up the document. I wrote the script based on a MS Word documented saved as HTML (so it is hard coded to use those style names). Just noting it here in case useful to anyone who comes along this post in the future. http://alankent.me/2016/03/05/creating-a-kindle-book-using-microsoft-word-quick-note/