Use the figure tag for Markdown

By defautl ![...](...) is translated to <img src='...' alt='...'> in Markdown. This demo shows how to use the HTML5 <figure> tag:

library(knitr)
knit_hooks$set(plot = function(x, options) {
  paste('<figure><img src="',
        opts_knit$get('base.url'), paste(x, collapse = '.'),
        '"><figcaption>', options$fig.cap, '</figcaption></figure>',
        sep = '')
})

Test:

plot(rnorm(100))

This is a very simple-minded plot hook; you should take a look at knitr's default definition if you want to improve this hook function.



Try the parsermd package in your browser

Any scripts or data that you put into this service are public.

parsermd documentation built on May 20, 2021, 5:08 p.m.