feat: add support for customizable QR code text/caption in poster margin

Change-Id: I731628490502fb5af4333ec27105dc61396e6ef8
diff --git a/R/posterdown_html.R b/R/posterdown_html.R
index a321229..87a6e05 100644
--- a/R/posterdown_html.R
+++ b/R/posterdown_html.R
@@ -23,19 +23,39 @@
 }
 
 
+#' @param url Target URL for the QR code
+#' @param logo Optional path to a logo image to place in the center of the QR code
+#' @param text Optional text/caption to display below the QR code (alias: \code{caption})
+#' @param caption Alias for \code{text}
 #' @description Print html code for a linked qr code to the given url
 #' @importFrom qrcode add_logo qr_code generate_svg
 #' @export
-qrlink <- function(url, logo = NULL) {
+qrlink <- function(url, logo = NULL, text = NULL, caption = text) {
   tmp <- tempfile(fileext = ".svg")
   qrcode <- qrcode::qr_code(url, ecl =  if(is.null(logo)) "L" else "H")
   if(!is.null(logo)) {
     qrcode <- qrcode::add_logo(qrcode, logo, ecl = "L")
   }
   qrcode::generate_svg(qrcode, tmp,  show = FALSE)
-  return(paste0( sprintf('<a class="qrcode" href="%s"><img class="qrcode">', url),
-                 gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
-                 '</img></a>'
-         ))
+
+  cap_html <- if (!is.null(caption) && nchar(trimws(caption)) > 0) {
+    sprintf('<span class="qrcode-caption">%s</span>', caption)
+  } else {
+    ""
+  }
+
+  if (nchar(cap_html) > 0) {
+    return(paste0( '<div class="qrcode-container"><a class="qrcode" href="', url, '"><img class="qrcode">',
+                   gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
+                   '</img></a>',
+                   cap_html,
+                   '</div>'
+           ))
+  } else {
+    return(paste0( sprintf('<a class="qrcode" href="%s"><img class="qrcode">', url),
+                   gsub("\r?\n|\r", "", readChar(tmp, 1e7)),
+                   '</img></a>'
+           ))
+  }
 }