{emayili} Right-to-Left

Yoav Raskin suggested that it would be useful to support right-to-left (RTL) text in {emayili}, so that languages like Hebrew, Arabic and Aramaic would render properly. I’ll be honest, this was not something that I had previously considered. But agreed, it would be a cool feature.

library(emayili)

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

RTL in CSS

The first step to make this happen was writing a short CSS file, rtl.css.

.rtl {
  direction: rtl;
  color: green;
}

body {
  margin: 20px 0px;
}

figure {
  margin-bottom: 20px;
}

.rtl figcaption {
  direction: inherit;
}

This makes use of the CSS direction property (which by default is ltr), setting it to rtl. I’m also colouring the RTL text in green, just to make things super clear.

I put together a simple .Rmd file to test, rtl.Rmd, rendered it into a message and then dispatched.

envelope() %>%
  subject("Right-to-Left Text") %>%
  render("rtl.Rmd", css_files = "rtl.css")

The extra CSS is included via the css_files parameter.

馃毃 If you want this to work nicely on Gmail then you’ll also need to set include_css = c("rmd", "highlight") because Gmail doesn’t currently appreciate Bootstrap CSS.

In the interests of brevity the contents of `rtl.Rmd` have been appended to the end of the post.

And this is what the delivered email looks like:

Having a rtl class allowed me to mix both left-to-right and right-to-left content in the same message. In reality this is a rather unlikely requirement. To use RTL for the entire message just adapt the CSS as follows:

body {
  direction: rtl;
}

If there are other tweaks that I can make on {emayili} to ensure that it supports your requirements, please raise an issue on the repository.


The `{emayili}` package is developed & supported by [Fathom Data](https://www.fathomdata.dev).


Here are the contents of rtl.Rmd:

---
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non magna
magna. Etiam eu sapien nulla. Cras ac lectus non urna scelerisque porttitor ac
non tortor.

<div class="rtl">
爪讞讜拽 讛诪注讘讜专转, 诪讛讚讜讘讬诐 砖诇 讛讻专讬转 讛讞讜驻砖讬转. 诪讬 专讜爪讛 诇驻住驻住, 注爪讜讘 讘讞爪专 讛讗讞讜专讬转, 讻讚
专讱. 注讻砖讬讜 讛讻讗讘 砖诇 讛讻讗讘 讛讜讗 诇讗 讛讻讗讘 砖诇 讛讟专讚讛, 讛爪讜专讱 砖诇 讗讙诪讬 讛讞诇讘讜谉 砖诇 讛转驻讜讝.
讗诇诪谞讟 讻诇砖讛讜, 鈥嬧嬜曌捵 诇讗 讬住讜讚 讻讬诪讬 砖诇 谞讚诇"谉, 诪专讗讬转 注讬谉 砖诇 诪讙讜讜谉 讻诇讬 专讻讘 诇谞讞讜转, 专讙注
诇驻谞讬 讛住驻讚 讛讞讬讬诐. 讗谞讬讗住 讛讜讗 诪讞讘专 专讻讬讘 讛诪讞讬专. 讗讬谉 驻讞讚 讗诇讗 讗诐 诇讛讬讜转 讻谞讬诐. 讗谞讬 讞讬
讘诪讬讬住专 讛注爪讜讘 砖诇 讛讻讚讜专讙诇 砖诇讬, 讘住诪讱 讛讝谉 讻诪讜讘谉. 讗讘诇 讛诪注谞讛 讜讛拽砖转讜转, 讗讜 拽爪讜转 讛讗讜专拽讬诐.
讗诇 讛讗讙诐 讗讜 诇驻谞讬讜. 讛讝诪谉 砖诇 讛注诪拽 诇讜拽讞. 讗驻讬诇讜 讛驻讞讚 诪讛驻讞讚, 讛拽砖转讜转 讗讜 讛诪注讘讜专转, 讗转转
讛讗讬谞讟专谞讟.
</div>

```{r pressure, out.width="50%", fig.cap="讻讬转讜讘 讚诪讜转", fig.class="rtl"}
par(mar = c(5, 4, 1, 1))
plot(pressure, xlab = "讟侄诪驻侄旨专指讟讜旨专指讛", ylab = "诇址讞址抓", mar = c(5, 4, 0, 2))
```

<div class="rtl">
讛诪讞诇讛 谞讜砖讗转 讗转 讛住讘讬专讜转 诇住讜祝 讛砖讘讜注, 讜讛驻讞讚 诪讛讻讚讜专讙诇 拽砖讛. 讗讘诇 讛讗专讬讛 讜讛讗专讬讛 讜讛讬诇讚讬诐
谞诪爪讗讬诐 讘诪讬讟讛. 讝讛 讘专讜讟讘 爪专讬讱 诇讛讙讬讚. 讗讘诇 诪讘讞讬谞转讜, 爪专讜转 讛讞讬讬诐 诪讜转讬专讜转 讛专讘讛 讞讬讬诐,
讛拽专讬拽讟讜专讛 讝拽讜拽讛 诇讗专讜住讬诐. 注讻砖讬讜 讗谞讬 砖讜谞讗 讗转 讛讙讜专诪讬诐, 诇讗 讗转 讛讻讗讘 讜诇讗 讗转 讛住讘讬讘讛,
讛讻谞讬住讛 拽诇讛. 注讻砖讬讜 讛讻谞讬住讛 诇讞讬讬.
</div>

Cras fringilla nunc in tellus sagittis accumsan. Mauris nisi tellus, congue sit
amet turpis nec, accumsan lacinia neque. Nulla facilisi.

Translation from Latin to Hebrew courtesy of Google Translate.