{emayili} Rendering Plain Markdown

We’ve been able to attach text and HTML content to messages with {emayili}. But something that I’ve really been wanting to do is render Markdown directly into an email.

In version 0.4.19 I’ve added the ability to directly render Plain Markdown into a message. That version is not on CRAN, so you’ll need to install from GitHub.

remotes::install_github("datawookie/emayili", ref = "v0.4.19")

Load the package and check the version.

library(emayili)

packageVersion("emayili")
[1] '0.4.19'

The new render() method will handle Plain Markdown either as a character vector or from a file.

Markdown String 

Let’s start with Markdown in a character vector.

email <- envelope() %>%
  render("[This](https://www.google.com) is a link.")

What’s the raw email document look like?

print(email, TRUE)
Date:         Sat, 11 Sep 2021 03:42:18 GMT
X-Mailer:     {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="28353539f2a233f353c181725361818"

--28353539f2a233f353c181725361818
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

<p><a href=3D"https://www.google.com">This</a> is a link.</p>


--28353539f2a233f353c181725361818--

The Markdown has been translated into HTML and inserted as a text/html MIME element.

Markdown in a File 

You’re more likely to have your Markdown in a file. Suppose that the file message.md contains the following:

[This](https://www.google.com) is a link.

- One
- Two
- Three

![](https://cran.r-project.org/Rlogo.svg)

The render() function will identify its argument as a file path and render the contents of the file.

email <- envelope() %>%
  render("message.md")

And this is what the resulting MIME message looks like:

print(email, TRUE)
Date:         Sat, 11 Sep 2021 03:42:18 GMT
X-Mailer:     {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="14133862a830263231d26271f2230"

--14133862a830263231d26271f2230
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

<p><a href=3D"https://www.google.com">This</a> is a link.</p>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
<p><img src=3D"https://cran.r-project.org/Rlogo.svg" alt=3D"" /></p>


--14133862a830263231d26271f2230--

This new feature partially scratches a persistent itch. But I’ll only be satisfied when I can render R Markdown straight into an email. Stay tuned next week.