Code Monkey home page Code Monkey logo

Comments (10)

mitchelloharawild avatar mitchelloharawild commented on August 16, 2024 1

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?

from icons.

mitchelloharawild avatar mitchelloharawild commented on August 16, 2024 1

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.

from icons.

mitchelloharawild avatar mitchelloharawild commented on August 16, 2024 1

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

from icons.

garthtarr avatar garthtarr commented on August 16, 2024 1

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:

Screen Shot 2022-04-07 at 10 03 41 pm

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)

from icons.

garthtarr avatar garthtarr commented on August 16, 2024

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} 

from icons.

yihui avatar yihui commented on August 16, 2024

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.

from icons.

mitchelloharawild avatar mitchelloharawild commented on August 16, 2024

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.

from icons.

yihui avatar yihui commented on August 16, 2024

Awesome. Thanks for the careful investigation!

from icons.

garthtarr avatar garthtarr commented on August 16, 2024

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

from icons.

mitchelloharawild avatar mitchelloharawild commented on August 16, 2024

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

from icons.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.