diff --git a/R/hooks-html.R b/R/hooks-html.R index 0cd63dd7dd..742e090ca3 100644 --- a/R/hooks-html.R +++ b/R/hooks-html.R @@ -64,6 +64,16 @@ hook_animation = function(options) { ), cap) } +.img.id = function(options) { + sprintf( + 'id="%s"', + paste0( + options$fig.lp, options$label, + if (options$fig.num > 1L && options$fig.show == 'asis') options$fig.cur + ) + ) +} + # a wrapper to upload an image and return the URL .upload.url = function(x) { opts_knit$get('upload.fun')(x) diff --git a/R/hooks-md.R b/R/hooks-md.R index 6319b1ceef..995ea306c4 100644 --- a/R/hooks-md.R +++ b/R/hooks-md.R @@ -63,8 +63,9 @@ hook_plot_md_base = function(x, options) { d1 = if (plot1) sprintf('
\n', css_text_align(a)) d2 = sprintf('

%s

', cap) img = sprintf( - '%s', - paste0(opts_knit$get('base.url'), .upload.url(x)), alt, .img.attr(w, h, s) + '%s', + paste0(opts_knit$get('base.url'), .upload.url(x)), alt, .img.attr(w, h, s), + .img.id(options) ) img = add_link(img) # whether to place figure caption at the top or bottom of a figure