Skip to content

Commit

Permalink
added .img.id for image id for epub to try to fix rstudio/bookdown#766
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Aug 28, 2019
1 parent ebee940 commit fda0660
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions R/hooks-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions R/hooks-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ hook_plot_md_base = function(x, options) {
d1 = if (plot1) sprintf('<div class="figure"%s>\n', css_text_align(a))
d2 = sprintf('<p class="caption">%s</p>', cap)
img = sprintf(
'<img src="%s" alt="%s" %s />',
paste0(opts_knit$get('base.url'), .upload.url(x)), alt, .img.attr(w, h, s)
'<img src="%s" alt="%s" %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
Expand Down

0 comments on commit fda0660

Please sign in to comment.