icons
icons copied to clipboard
Test icon support within other packages / locations
Before release it would be great to check that icons work in non-standard locations including:
- tables (kable, gt, DT, etc.)
- navbars (bookdown, pkgdown)
- slide decks
@apreshill has some examples where the font based implementation would work in tables.
Hey Mitch,
Some comments about implementation in bookdown
- There's an issue compiling with to
epub_book
format
Error in knit_print.icon(v$value, inline = TRUE, options = opts_chunk$get()) :
Icons for this format is currently not supported
- If a chapter/section heading has an icon in it, then the url is horrible (and un-clickable). There's an easy way around this by specifying your own reference, e.g. this works just fine:
## Git and GitHub `r icon::fontawesome("github")` {#github}
Thanks Garth.
-
I've added epub support, however I don't know how to appropriately scale the image size as
{height=1em}
seems to be ignored. If you have any suggestions for this, that would be fantastic. -
I don't know how to fix this one, although I'm pleased to see that the icon displays correctly in the navbar and title (and with the workaround it works fine). @yihui: Is there some way to suppress/control
knit_print
outputs being used in creating default div ids?
I don't think the ids are created by knit_print
, but Pandoc instead. They are generated automatically by default: https://pandoc.org/MANUAL.html#heading-identifiers I'd strongly recommend using a manual id instead of relying on the auto ids.
Thanks Yihui. What I intended to ask was if knit_print()
output (or generally, non-text output) can be suppressed from pandoc's auto identifiers. Reading into pandoc's auto ids I suspect this isn't possible, as from what I understand any content in the header will be used to generate an ID.
Some insight into the knitr mechanics of plot outputs would be useful, as
# Title `r plot(rnorm(10))`
does not show the plot in the title, but:
# Title `r knitr::asis_output(letters)`
does show the letters in the title.
After some further investigation, it seems that using htmltools::htmlPreserve()
in markdown titles preserves the code into the auto ids. Removing this produces ids which ignore the icon code.
Awesome. Thanks for the careful investigation!
Looks like the distill package returns html5
in response to knitr::opts_knit$get("rmarkdown.pandoc.to")
which means that the icon package currently complains about Icons for this format is currently not supported
for distill. Adding "html5"
as an option in knit.R seems to fix the issue, but I haven't tested widely and I'm not sure if this is just a naiive hack. I've submitted it as a totally trivial pull request #42
Looks like {icon}
should consider all pandoc output formats, as listed here: https://pandoc.org/MANUAL.html#option--to
All common pandoc output formats should now be handled, with a fallback to png and markdown image inputs (cbda25610fe09480bad8658ac4b4af49ff2467b9)
Not sure if I should start a new issue or if this is an extension of this issue, but I've found icons has a strange interaction with Quarto (aka R Markdown 2.0 that all the cool kids seem to be getting excited about). Specifically I've found the icons generate extra output that breaks the formatting when they're included in lists or tables. I'm not sure if this is a Quarto issue or something that can be resolved at the icons package end, but just throwing it out there in case you have any ideas @mitchelloharawild
Example:
---
title: "Icons, meet Quarto!"
format: html
editor: visual
---
```{r, include=FALSE}
library(icons)
```
This works ok:
```{r icon-chunk}
icons::fontawesome("star", style = "solid")
```
as does the inline version:
`r icons::ionicons("rocket")`
but not so much in a list:
- first list item
- second list item with a star `r icons::fontawesome("star", style = "solid")`
- third list item
or a table:
| Col1 | Col2 | Col3 |
|------|------|------|
| A1 | A2 | A3 |
| B1 | B2 with a star `r icons::ionicons("rocket")` | B3 |
| C1 | C2 | C3 |
This is the output I see:

Inspecting the difference in the final HTML between a RMD and a Quarto I see this:
R Markdown (works fine)
<ul>
<li>first list item</li>
<li>second list item with a star
<svg viewBox="0 0 576 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg">
<path d="M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"></path></svg></li>
<li>third list item</li>
</ul>
Quarto (mangles the list adding in the ::: stuff)
<ul>
<li>first list item</li>
<li>second list item with a star ::: {.cell-output-display}</li>
</ul>
<svg viewbox="0 0 576 512" style="height:1em;position:relative;display:inline-block;top:.1em;" xmlns="http://www.w3.org/2000/svg"> <path d="M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"></path></svg>
<p>:::</p>
<ul>
<li>third list item</li>
</ul>
> sessioninfo::session_info(pkgs = "remotes")
─ Session info ───────────────────────────────────────────────────────────────────────────
setting value
version R version 4.1.3 (2022-03-10)
os macOS Monterey 12.3.1
system x86_64, darwin17.0
ui RStudio
language (EN)
collate en_AU.UTF-8
ctype en_AU.UTF-8
tz Australia/Sydney
date 2022-04-07
rstudio 2022.02.1+461 Prairie Trillium (desktop)
pandoc NA
─ Packages ───────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
remotes * 2.4.2 2021-11-30 [1] CRAN (R 4.1.0)