Use footnote multiple times in HTML Quarto - html

I would like to use a single footnote multiple times in HTML Quarto. The problem is that once I create a footnote and use it twice, it will be shown as two footnotes. Here is a reproducible example:
---
title: "Footnote multiple times"
editor: visual
format: html
---
Some example text for a footnote[^1].
Some example text for same footnote[^1].
[^1]: Example footnote.
Output:
As you can see, the footnote is shown as two separate footnotes (duplicated) while I created one footnote. So I was wondering if anyone knows how to create one footnote and use it multiple times in HTML Quarto?

We can sort of mimic how quarto would have generated the html code creating for footnotes to get similar appearances (that's why I have used r function so that I don't have to write the same thing multiple times).
---
title: "Footnote multiple times"
format: html
---
```{r}
#| echo: false
gen_fn <- function(n, id) {
# n is number of footnote
# id is a unique id for that footnote
paste0('<sup>', n, '</sup>')
}
```
Some example text for a footnote`r gen_fn(1, "fn1")`
Some example text for same footnote`r gen_fn(1, "fn1")`
Another text containing different footnotes`r gen_fn(2, "fn2")`
```{=html}
<footer>
<h2>Footnotes</h2>
<ol style="padding-left: 1rem;">
<li id="fn1"><p>Example footnote.</p></li>
<li id="fn2"><p>More footnote.</p></li>
</ol>
</footer>
```

Related

Scrape Bolded Text with rvest

I am scraping in R with rvest. I am trying to extract a list of dollar signs. Either $, $$, or $$$. The site shows $$$, and bolds in dark black 1, 2, or 3 of the symbols. With my current code, it is drawing $$$ for every single page.
This is an example of the HTML code for the site section (This one has one $ bolded in dark black). I am trying to extract one "$" for this example:
<div class = "container">
<div class = "value">
<strong>
" $"
<span>$$</span>
</strong>
</div>
<div class ="label">Price</div>
I am currently using code something like this. It is looping through 1000s of similar pages. All are pulling $$$.:
html <- read_html(website) # save html from page
text <- html_elements(html, ".value") %>%
html_text(trim = T) # save list of text in this section of the page
price <- text[length(text)] # save the price, it is the last text section in the list

Multiple bibliographies in HTML, using keywords - is it possible?

I am making a CV in R Markdown, and I have the following code that uses Latex to render multiple bibliography sections based on the keywords={} argument in the bibtex reference:
---
header-includes: \usepackage{tikz,xcolor,listings,CormorantGaramond,fontawesome,academicons,mfirstuc,fancyhdr,multicol}
output:
bookdown::pdf_document2:
citation_package: biblatex
toc: no
latex_engine: lualatex
biblio-style: apa
bibliography: MyPubs.bib
---
\underline{\textbf{Publications}}
\begin{refsection}
\setlength\bibitemsep{\baselineskip}
\nocite{*}
\noindent\printbibliography[heading=none, keyword = mypapers]
\end{refsection}
\underline{\textbf{Presentations}}
\begin{refsection}
\setlength\bibitemsep{\baselineskip}
\nocite{*}
\printbibliography[heading=none, keyword = mypresentations]
\end{refsection}
The resulting behavior is as follows: R Markdown renders a PDF with two separate bibliographies: a Publication section that pulls references from my .bib file that have the mypublications keywords, and a separate section for Presentations (from refs with mypresentations keywords).
The output is PDF, but how do you duplicate this behavior in HTML?
I'm having a hard time finding info on this; is it possible? Thank you in advance for any guidance you can provide.

How to exclude the not evaluated R markup sections from the ToC of the resulting HTML document?

I am writing an R/Shiny code that generates HTML reports for my users' data using an R markup template. I want to give the user the option to omit certain sections from the report. Which is easy to do for the sections themselves, but not obvious for the sections' headlines and their ToC entries. Any advice would be greatly appreciated!
My code passes the list of sections to include in the report via the params variable of the rmarkdown::render function. And the omitted sections of the R markup file are indeed not evaluated. However, the ToC entries and headlines for those (empty) sections still end up in the resulting HTML file. I browsed the manual but could not find any way to use the markup code parameters to exclude desired sections of the markup file.
---
output:
html_document:
theme: yeti
df_print: kable
toc: true
toc_float:
collapsed: true
smooth_scroll: false
params:
ExpData: data.frame()
set_title: "My Data Report"
Sections_to_include: list()
title: "`r params$set_title`"
---
.....................................
.....................................
.....................................
# ANOVA
```{r , eval = ( "ANOVA" %in% params$Sections_to_include)}
# Here be the code that generates my ANOVA table
# lme_model is calculated from params$ExpData in the preceding
# code chunks
kable(ANOVA(lme_model))
```
If the params$Sections_to_include list does not include the element "ANOVA" then the code chunk above will not be evaluated and the ANOVA table won't be printed. However, the section headline ANOVA will still be included in the HTML document preceding an empty section, and the ToC will contain a link to that headline. Which is of course what the
# ANOVA
line instructs R markup to do. I wonder if there is any parameter that would allow me to instruct the R markup renderer to ignore that line.
One solution I can see is to change the workflow to (i) generate a customized R markup document from the basic template according to the options desired (e.g., using UNIX command line tools), and (ii) then render the customized markup file into an HTML doc. But I wonder if R markup / knitr provide a simpler built-in solution?
Thank you all!
You can do it using the "asis" engine. It's likely helpful to write a little function to decide on whether something should be included. Here's your example modified to leave out "ANOVA", but include two other sections.
---
output:
html_document:
theme: yeti
df_print: kable
toc: true
toc_float:
collapsed: true
smooth_scroll: false
params:
ExpData: data.frame()
set_title: "My Data Report"
Sections_to_include: ["Other", "More"]
title: "`r params$set_title`"
---
.....................................
.....................................
.....................................
```{r include=FALSE}
library(knitr)
include <- function(section) {
section %in% params$Sections_to_include
}
```
```{asis , echo=include("Other")}
# Other section
This is a section that I do want to include, this time.
```
```{asis echo=include("ANOVA")}
# ANOVA
```
```{r , echo = include("ANOVA"), eval = include("ANOVA")}
# Here be the code that generates my ANOVA table
# lme_model is calculated from params$ExpData in the preceding
# code chunks
kable(ANOVA(lme_model))
```
```{asis , echo=include("More")}
# More
So is this one.
```
I'm not sure how to programmatically generate that vector of section names in Sections_to_include from within YAML, but you can always pass parameter values in your call to rmarkdown::render.

Create an NCX file with Notepad++ and Regular expression

I have a HTML Table of Contents page containing list of book chapters with hyperlinks:
Multimedia Implementation<br/>
Table of Contents<br/>
About the Author<br/>
About the Technical Reviewers<br/>
Acknowledgments<br/>
Part I: Introduction and Overview<br/>
Chapter 1. Technical Overview<br/>
...
I want create NCX file for a Kindle book which must contain details as follows:
<navPoint id="n1" playOrder="1">
<navLabel>
<text>Multimedia Implementation</text>
</navLabel>
<content src="final/main.html"/>
</navPoint>
<navPoint id="n2" playOrder="2">
<navLabel>
<text>Table of Contents</text>
</navLabel>
<content src="final/toc.html"/>
</navPoint>
<navPoint id="n3" playOrder="3">
<navLabel>
<text>About the Author</text>
</navLabel>
<content src="final/pref01.html"/>
</navPoint>
...
I'm using Notepad++: is it possible automate this process with regular expression?
You cannot do everything using regex.. you can split the problem into two parts..
generate strings like <navPoint id="n1" playOrder="1"> using program logic (increment variable)
remaining you can do with regex
Use the following regex to match:
<a\shref="([^"]*)">([^<]*)<\/a><br\/>
And replace with:
(generated string)<navLabel>\n<text>\2</text>\n<content src="\1"/>\n</navPoint>
See DEMO
Yes, it is possibly to replace the links with <navpoint> tags. The only thing I found no solution for is the incremental numbering of the <navpoint> attributes id and playOrder...
The following regex will do most of the work:
/^<a[^>]*href="([^"]+)"[^>]*([^<]+).*$/gm
substitute with:
<navpoint id="n" playOrder="">\n<navLabel><text>$2</text></navLabel>\n<content src="$1" />\n</navpoint>\n
Regex details
/^<a .. only parse lines that start with an `<a` tag
.*href=" .. find the first occurance of `href="`
([^"]+) .. capture the text and stop when a " is found
"[^>]*> .. find the end of the <a> tag
([^<]+) .. capture the text and stop when a < is found (i.e. the </a> tag)
.*$/ .. continue to end of the line
gm .. search the whole string and parse each line individually
More detailled (but also more confusing) explanation is here:
https://regex101.com/r/gA0yJ2/1
This link also demonstrates how the regex is working. You can test changes there if you like

Automatically add some kind of text to text?

So basically this:
Is there a program or something where you can input text and then it automatically adds html tags at the beginning and end of the inputted text, for example:
I type the text: "Life finds a way"
Then the program makes it like this:
<p align="center">"Life finds a way"</p>
Matthew
Have a look at Markdown language.
It's exactly what's used when you post something on StackOverflow. Everything you write is converted to html behind the scenes (that's also why you can't print a tag without using code notation in a post).
So simple text is converted to a <p> tag, unless you break two lines with an empty line.
To create an header, just use :
Header
------
which renders like this:
Header
Or like this :
# Header
## Header
### Header
which renders :
Header
Header
Header
Creating lists is also very handy :
* first item
* second item
which renders :
first item
second item
or if you like numbered lists :
1. first item
2. second item
first item
second item
Bold is as simple as : **Bold**
Italic is : *Italic*
Finally, links are simple:
The wikipedia article is linked like this :
[The wikipedia article](http://en.wikipedia.org/wiki/Markdown)