From b0b475d5c43b9ab67161daec2cce43ced96f9ca4 Mon Sep 17 00:00:00 2001 From: Adam Ryczkowski Date: Thu, 13 Jul 2017 10:47:58 +0200 Subject: [PATCH] Add an option to pandoc.image.return so it can insert Markdown attributes.\n I use it with the pandoc-fignos pandoc plugin to insert image number. --- R/pandoc.R | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/R/pandoc.R b/R/pandoc.R index 930d2b3b..86499563 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -215,20 +215,28 @@ pandoc.link <- function(...) #' pandoc.image('foo.png') #' pandoc.image('foo.png', 'Nice image, huh?') #' @references John MacFarlane (2012): _Pandoc User's Guide_. \url{http://johnmacfarlane.net/pandoc/README.html} -pandoc.image.return <- function(img, caption = storage$caption) { +pandoc.image.return <- function(img, caption = storage$caption, pandoc_attributes = '') { check_caption(caption) if (is.null(caption)) { caption <- '' } - + if (pandoc_attributes=='') { + if (!is.null(attr(img, 'pandoc_attributes'))) { + pandoc_attributes <- attr(img, 'pandoc_attributes') + } + } + ## truncating caption buffer if needed if (!is.null(storage$caption)) { storage$caption <- NULL } - - sprintf('![%s](%s)', caption, img) + if(pandoc_attributes=='') { + sprintf('![%s](%s)', caption, img) + } else { + sprintf('![%s](%s){%s}', caption, img, pandoc_attributes) + } } #' @export