mitchelloharawild / icons

R package to easily insert web icons to RMarkdown
https://pkg.mitchelloharawild.com/icons
313 stars 43 forks source link

Test icon support within other packages / locations #33

Open mitchelloharawild opened 5 years ago

mitchelloharawild commented 5 years ago

Before release it would be great to check that icons work in non-standard locations including:

@apreshill has some examples where the font based implementation would work in tables.

garthtarr commented 4 years ago

Hey Mitch,

Some comments about implementation in bookdown

  1. 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
  1. 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} 
mitchelloharawild commented 4 years ago

Thanks Garth.

  1. I've added epub support, however I don't know how to appropriately scale the image size as ![](<path>){height=1em} seems to be ignored. If you have any suggestions for this, that would be fantastic.

  2. 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?

yihui commented 4 years ago

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.

mitchelloharawild commented 4 years ago

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.

mitchelloharawild commented 4 years ago

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.

yihui commented 4 years ago

Awesome. Thanks for the careful investigation!

garthtarr commented 3 years ago

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

mitchelloharawild commented 3 years ago

Looks like {icon} should consider all pandoc output formats, as listed here: https://pandoc.org/MANUAL.html#option--to

mitchelloharawild commented 3 years ago

All common pandoc output formats should now be handled, with a fallback to png and markdown image inputs (cbda25610fe09480bad8658ac4b4af49ff2467b9)

garthtarr commented 2 years ago

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:

icons::fontawesome("star", style = "solid")

as does the inline version:

r icons::ionicons("rocket")

but not so much in a list:

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:

<img width="857" alt="Screen Shot 2022-04-07 at 10 03 41 pm" src="https://user-images.githubusercontent.com/2189134/162194428-7dcd6915-4373-4547-bcd5-3da8e850bd56.png">

Inspecting the difference in the final HTML between a RMD and a Quarto I see this:

R Markdown (works fine)

Quarto (mangles the list adding in the ::: stuff)

:::

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)