insert hyperlink into figure caption?

Is there a way to insert hyperlinks into figure captions? I have tried the following:

#```{r fig.cap='[This link](>)[That link](>)'  }  
#```{r fig.cap='<a href=">link</a>'}  
# ```{r fig.cap='[This link](>)'  }

I can edit the knitted html, but is there a better way?

For now, this would require to use an output format that support bookdown feature b/c you would need to use Text Reference here: 2.2 Markdown extensions by bookdown | bookdown: Authoring Books and Technical Documents with R Markdown

The aim is that your caption is processed by Pandoc so that Markdown get converted to the correct form, and bookdown post processing will insert the text reference in the right place.

We may find another more global way to allow this but currently this is a limitation with figure captions if you want to use Markdown syntax.

However, if you are using a link without changing the text, this should work and also, with raw HTML would work if you use correct quoting

See this example. bookdown::html_document2 is required for text reference to work.

title: "Caption"
    keep_md: true

(ref:cap) See this [link](

```{r fig.cap = '(ref:cap)'}  

```{r fig.cap="See this site"}  

```{r fig.cap = '<a href="">link</a>'}  

Thanks! I'll give it a try.

1 Like

This topic was automatically closed 21 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.