Turning an svg icon into a clickable link in inline text

Probably a silly question but is there any ways to wrap an svg image using <svg></svg> tags in a markdown-style link []()? The idea would be to make a clickable svg icon using fontawesome::fa() that I can use in inline text or that I could append to text via paste() or glue::glue() for example.

Hi @arangaca,

what about:

---
title: 'Posit 202750'
output: html_document
date: "2025-06-20"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Something like this?

```{r echo=FALSE}
generate_link_with_icon <- function(href, text, name, color) {
  cat(
    '<a href="',
    href,
    '" target="_blank">',
    text,
    fontawesome::fa(name = name, fill = color),
    '</a>'
  )
}
```


```{r results='asis', echo=FALSE}
generate_link_with_icon(href = "https://github.com", "Super nice link text", "github", "black")
```

Output:

image

2 Likes

Hi @vedoa ,

Thank you for your input. This will only work when rendering as HTML though. I know that svg images usually don't work well with PDFs but using `r fontawesome::fa("github")` also works in PDF documents. However, I can't make it work if I add a link or use paste() to add some text before the logo. Ideally, I'm looking for a solution that works with any format.

The obvious solution would simply consist in writing the image onto the disk and importing it in Quarto (this is what fontawesome::fa_png() does) but I don't really like the idea of saving the logo on the disk in that case.

Hi @arangaca

i don't think you will find an easy way for all formats (easy in the sense that you don't have to check for what output your render).

You can trick rmarkdown into doing things for you like this

---
title: "202750"
output:
  pdf_document: default
---

## PDF Output

This will show a GitHub icon in **PDF** output:
[
```{r, echo=FALSE, results='asis'}
library(fontawesome)
  fa("github")
```
](https://github.com)

which results in

but again this is only a solution for pdf (latex really). Basically the r code chunk is on the fly converted into a image and then included. The markdown syntax [ ]() is just used to trick pandoc to converting the image to a link.

1 Like

Thank you very much. That's a cool solution, albeit somewhat hacky.

I guess now I only need to decide what solution suits me best between using fontawesome::fa() or saving the logo on the disk.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.