Add linked qrcode: qrlink

Change-Id: I344ae90b5cc6aad9f61ff5ac9e42fe8680af7164
diff --git a/R/posterdown_html.R b/R/posterdown_html.R
index e391b92..8ac3ea5 100644
--- a/R/posterdown_html.R
+++ b/R/posterdown_html.R
@@ -62,3 +62,20 @@
                                   css = NULL) {
   pagedown::poster_relaxed(..., css = css, template = template)
 }
+
+#' @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) {
+  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, 1e5)),
+                 '</img></a>'
+         ))
+}
+