{emayili} Rendering Plain Markdown

[This article was first published on R | datawookie, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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.

library(emayili)

The 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:         Fri, 10 Sep 2021 09:15:16 GMT
X-Mailer:     {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="3e11212a3e253d3112d314038331626"

--3e11212a3e253d3112d314038331626
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>


--3e11212a3e253d3112d314038331626--

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:         Fri, 10 Sep 2021 09:15:16 GMT
X-Mailer:     {emayili}-0.4.19
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="3c420353c27a23283a1a2a381a1a1f"

--3c420353c27a23283a1a2a381a1a1f
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>


--3c420353c27a23283a1a2a381a1a1f--

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.

To leave a comment for the author, please follow the link and comment on their blog: R | datawookie.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)