hugo_plot_hook: Plot hook for Hugo environment

hugo_plot_hookR Documentation

Plot hook for Hugo environment

Description

This knitr() plot hook uses the options in a knitr code chunk to generate some Hugo lines that after handling by Hugo processor will produce HTML code to display an image produced by an knitr code chunk. The last section of Details shows the HTML that can be generated.

Usage

hugo_plot_hook(x, options)

Arguments

x

Character string with the filename of a generated image relative with respect to the code folder

options

List with the chunk options

Details

After setting the hook with knitr::knit_hooks$set each time that an image is generated the function is called with the file name and the list with chunk options.

The function uses the chunk options:

  • hugoopts. This is a list with parameters for he Hugo shortcode figure . Possible parameters (no defaults except for caption and cappos) are:

    • class : 'class' to use in HTML figure statement

    • id : 'id' to use in HTML figure statement

    • link : 'href' to navigate to when image is clicked

    • target : 'target' to use when image is clicked. E.g. '_blank'

    • rel : 'rel' to use when image is clicked. E.g. 'nofollow'

    • src : 'url' of generated image

    • alt : 'alt-text' for image

    • caption : 'caption' to place below or above image. (default fig.cap chunk option)

    • cappos : position of caption ('below' or 'above' with default 'below')

    • width : 'width' of the image

    • height : 'height' of the image

    • attr : 'text' of the 'caption' link

    • attrlink : 'url' of the 'caption' link

Example of generated HTML:

```   hugoopts= list(link="https://www.hanoostdijk.nl",target="_blank",rel="nofollow",
```               alt="alt-text",caption="caption-text",width="500",
```               attrlink="https://www.hanoostdijk.nl",attr="click here")
results after Hugo processing in the following HTML:
```  <div class="hoqc-center" >
```    <figure>
```      <a href="https://www.hanoostdijk.nl" target="_blank" rel="nofollow">
```        <img src="index_files/figure-html/index-8-1.png"
```             alt="alt-text" width="500"/>
```      </a>
```      <figcaption>
```        <p>caption-text <a href="https://www.hanoostdijk.nl">click here</a></p>
```      </figcaption>
```    </figure>
```  </div >

Value

Character string to be processed by Hugo to create picture

Acknowledgement

Started with the idea from https://ropensci.org/technotes/2020/04/23/rmd-learnings/
This function use the Hugo shortcode figureHOQC that is an adaption of Hugo shortcode figureHOQC

Examples

## Not run: 
to define the hook:
```{r setup}
knitr::knit_hooks$set(plot = hugo_plot_hook)
```
to make use of it:
```{r hugoopts= list(alt="alt-text",caption="caption-text",width="500") }
plot(1:3,(3:1)^2)
```

## End(Not run)

HanOostdijk/HOQCutil documentation built on July 28, 2023, 5:56 p.m.