From 825384a38146f904465ab77771ef1b86f74e8ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Wed, 22 Jul 2020 14:27:08 +0200 Subject: [PATCH 1/3] Allow for markdown text - add `gm_markdown_body()` for a body in markdown - Markdown text is transformed into HTML using {markdown} - I updated doc and DESCRIPTION using `attachment::att_amend_desc()` as some deps in DESCRIPTION were not necessary anymore apparently --- DESCRIPTION | 12 +++++++----- NAMESPACE | 2 ++ R/mime.R | 19 +++++++++++++++++++ man/gm_auth.Rd | 6 +++--- man/gm_auth_configure.Rd | 2 +- man/gm_mime.Rd | 10 ++++++++++ man/gm_token.Rd | 2 +- 7 files changed, 43 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ec8de38..3c00148 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,6 +11,7 @@ BugReports: https://github.com/r-lib/gmailr/issues Depends: R (>= 3.0.0) Imports: + base, base64enc, crayon, gargle, @@ -18,17 +19,18 @@ Imports: jsonlite, lifecycle, magrittr, + markdown, + methods, mime, - rematch2 + rematch2, + stats Suggests: - covr, + graphics, knitr, - methods, - sodium, rmarkdown, testthat VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.1.1 Roxygen: list(markdown = TRUE) +RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE index 3de3552..2c9170f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -82,6 +82,7 @@ export(gm_insert_message) export(gm_label) export(gm_labels) export(gm_last_response) +export(gm_markdown_body) export(gm_message) export(gm_messages) export(gm_mime) @@ -140,3 +141,4 @@ import(base64enc) import(httr) importFrom(lifecycle,deprecate_soft) importFrom(magrittr,"%>%") +importFrom(markdown,markdownToHTML) diff --git a/R/mime.R b/R/mime.R index 0d4a877..f348aab 100644 --- a/R/mime.R +++ b/R/mime.R @@ -126,6 +126,25 @@ gm_html_body <- function(mime, mime } +#' @rdname gm_mime +#' @importFrom markdown markdownToHTML +#' @export +gm_markdown_body <- function(mime, + body, + content_type = "text/html", + charset = "utf-8", + encoding = "base64", + ...) { + + gm_html_body( + body = markdownToHTML(text = body, fragment.only = TRUE), + content_type = content_type, + charset = charset, + encoding = encoding, + ... + ) +} + HTML_PART <- 2L #' @param part Message part to attach diff --git a/man/gm_auth.Rd b/man/gm_auth.Rd index 608badc..7964258 100644 --- a/man/gm_auth.Rd +++ b/man/gm_auth.Rd @@ -26,7 +26,7 @@ always determined from the token itself, never from this argument. Use \code{NA} or \code{FALSE} to match nothing and force the OAuth dance in the browser. Use \code{TRUE} to allow email auto-discovery, if exactly one matching token is found in the cache. Defaults to the option named "gargle_oauth_email", -retrieved by \code{\link[gargle:gargle_options]{gargle::gargle_oauth_email()}}.} +retrieved by \code{\link[gargle:gargle_oauth_email]{gargle::gargle_oauth_email()}}.} \item{path}{JSON identifying the service account, in one of the forms supported for the \code{txt} argument of \code{\link[jsonlite:fromJSON]{jsonlite::fromJSON()}} (typically, a @@ -40,11 +40,11 @@ permissions for each scope. and \code{gm_scopes()} to return a vector of the available scopes.} \item{cache}{Specifies the OAuth token cache. Defaults to the option named -"gargle_oauth_cache", retrieved via \code{\link[gargle:gargle_options]{gargle::gargle_oauth_cache()}}.} +"gargle_oauth_cache", retrieved via \code{\link[gargle:gargle_oauth_cache]{gargle::gargle_oauth_cache()}}.} \item{use_oob}{Whether to prefer "out of band" authentication. Defaults to the option named "gargle_oob_default", retrieved via -\code{\link[gargle:gargle_options]{gargle::gargle_oob_default()}}.} +\code{\link[gargle:gargle_oob_default]{gargle::gargle_oob_default()}}.} \item{token}{A token with class \link[httr:Token-class]{Token2.0} or an object of httr's class \code{request}, i.e. a token that has been prepared with diff --git a/man/gm_auth_configure.Rd b/man/gm_auth_configure.Rd index 087a0d3..4d1499f 100644 --- a/man/gm_auth_configure.Rd +++ b/man/gm_auth_configure.Rd @@ -35,7 +35,7 @@ used to make it easier to identify different applications.} \value{ \itemize{ \item \code{gm_auth_configure()}: An object of R6 class -\link[gargle:AuthState-class]{gargle::AuthState}, invisibly. +\link[gargle:AuthState]{gargle::AuthState}, invisibly. \item \code{gm_oauth_app()}: the current user-configured \code{\link[httr:oauth_app]{httr::oauth_app()}}. } diff --git a/man/gm_mime.Rd b/man/gm_mime.Rd index cdeac48..9a59cff 100644 --- a/man/gm_mime.Rd +++ b/man/gm_mime.Rd @@ -9,6 +9,7 @@ \alias{gm_subject.mime} \alias{gm_text_body} \alias{gm_html_body} +\alias{gm_markdown_body} \alias{gm_attach_part} \alias{gm_attach_file} \title{Create a mime formatted message object} @@ -44,6 +45,15 @@ gm_html_body( ... ) +gm_markdown_body( + mime, + body, + content_type = "text/html", + charset = "utf-8", + encoding = "base64", + ... +) + gm_attach_part(mime, part, id = NULL, ...) gm_attach_file(mime, filename, type = NULL, id = NULL, ...) diff --git a/man/gm_token.Rd b/man/gm_token.Rd index 6edaa46..75ddba5 100644 --- a/man/gm_token.Rd +++ b/man/gm_token.Rd @@ -7,7 +7,7 @@ gm_token() } \value{ -A \code{request} object (an S3 class provided by \link[httr:httr-package]{httr}). +A \code{request} object (an S3 class provided by \link[httr:httr]{httr}). } \description{ For internal use or for those programming around the Gmail API. From c85934e4c473af3e50db51b81d7f4c747b2fe840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Wed, 22 Jul 2020 14:34:07 +0200 Subject: [PATCH 2/3] remove base in DESCRIPTION --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3c00148..d303d9e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,6 @@ BugReports: https://github.com/r-lib/gmailr/issues Depends: R (>= 3.0.0) Imports: - base, base64enc, crayon, gargle, From 9dda811b6afc444a789a39a02d33fe8d304096a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rochette?= Date: Wed, 22 Jul 2020 14:35:56 +0200 Subject: [PATCH 3/3] add back covr --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index d303d9e..aaf020f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,6 +24,7 @@ Imports: rematch2, stats Suggests: + covr, graphics, knitr, rmarkdown,