- Add language argument to text(), html() and render()
- Allow language parameter to be Boolean
- Auto-detect language
Showing 4 of 11 files from the diff.
R/render.R
changed.
Newly tracked file
R/header-language.R
created.
Other files ignored by Codecov
man/mime-parameters.Rd
has changed.
man/html.Rd
has changed.
DESCRIPTION
has changed.
man/render.Rd
has changed.
R/emayili.R
has changed.
man/text.Rd
has changed.
@@ -22,6 +22,9 @@
Loading
22 | 22 | #' @param encoding How content is transformed to ASCII. Options are |
|
23 | 23 | #' \code{"7bit"}, \code{"quoted-printable"} and \code{"base64"}. Use \code{NA} |
|
24 | 24 | #' or \code{NULL} for no (or "identity") encoding. |
|
25 | + | #' @param language Langauge of content. If \code{FALSE} then will not include |
|
26 | + | #' language field. If \code{TRUE} then will attempt to auto-detect language. |
|
27 | + | #' Otherwise will use the specified language. |
|
25 | 28 | #' @param boundary Boundary string. |
|
26 | 29 | #' @param type The MIME type of the content. |
|
27 | 30 | #' @param children List of child MIME objects. |
@@ -69,6 +72,7 @@
Loading
69 | 72 | disposition = NA, |
|
70 | 73 | charset = NA, |
|
71 | 74 | encoding = NA, |
|
75 | + | language = NA, |
|
72 | 76 | format = NA, |
|
73 | 77 | boundary = emayili:::hexkey(), |
|
74 | 78 | type = NA, |
@@ -87,6 +91,7 @@
Loading
87 | 91 | disposition = disposition, |
|
88 | 92 | charset = charset, |
|
89 | 93 | encoding = encoding, |
|
94 | + | language = language, |
|
90 | 95 | format = format, |
|
91 | 96 | boundary = boundary, |
|
92 | 97 | children = children, |
@@ -318,6 +323,7 @@
Loading
318 | 323 | content_type(type, x$charset, x$boundary, x$format), |
|
319 | 324 | content_disposition(x$disposition), |
|
320 | 325 | content_transfer_encoding(x$encoding), |
|
326 | + | content_language(x$language, x$content), |
|
321 | 327 | x_attachment_id(x$cid), |
|
322 | 328 | content_id(x$cid) |
|
323 | 329 | ) |
@@ -41,6 +41,7 @@
Loading
41 | 41 | disposition = "inline", |
|
42 | 42 | charset = "utf-8", |
|
43 | 43 | encoding = "7bit", |
|
44 | + | language = FALSE, |
|
44 | 45 | interpolate = TRUE, |
|
45 | 46 | .open = "{{", |
|
46 | 47 | .close = "}}", |
@@ -53,7 +54,7 @@
Loading
53 | 54 | ||
54 | 55 | if (interpolate) content <- glue(content, .open = .open, .close = .close, .envir = .envir) |
|
55 | 56 | ||
56 | - | body <- text_plain(content, disposition, charset, encoding) |
|
57 | + | body <- text_plain(content, disposition, charset, encoding, language) |
|
57 | 58 | ||
58 | 59 | msg <- append(msg, body) |
|
59 | 60 |
@@ -84,6 +85,7 @@
Loading
84 | 85 | charset = "utf-8", |
|
85 | 86 | encoding = "quoted-printable", |
|
86 | 87 | css_files = c(), |
|
88 | + | language = FALSE, |
|
87 | 89 | interpolate = TRUE, |
|
88 | 90 | .open = "{{", |
|
89 | 91 | .close = "}}", |
@@ -104,7 +106,8 @@
Loading
104 | 106 | ||
105 | 107 | body <- text_html( |
|
106 | 108 | content, disposition, charset, encoding, |
|
107 | - | css = read_text(css_files) |
|
109 | + | css = read_text(css_files), |
|
110 | + | language = language |
|
108 | 111 | ) |
|
109 | 112 | ||
110 | 113 | msg <- append(msg, body) |
@@ -3,7 +3,8 @@
Loading
3 | 3 | params = NULL, |
|
4 | 4 | squish = TRUE, |
|
5 | 5 | css, |
|
6 | - | include_css |
|
6 | + | include_css, |
|
7 | + | language |
|
7 | 8 | ) { |
|
8 | 9 | stopifnot(is.null(params) || is.list(params)) |
|
9 | 10 |
@@ -154,7 +155,7 @@
Loading
154 | 155 | # Remove <meta> tag (a "Content-Type" <meta> inserted by {xml2}). |
|
155 | 156 | str_replace("<meta[^>]*>", "") |
|
156 | 157 | ||
157 | - | output <- text_html(output, squish = squish, css = css) |
|
158 | + | output <- text_html(output, squish = squish, css = css, language = language) |
|
158 | 159 | ||
159 | 160 | if (plain) { |
|
160 | 161 | output |
@@ -254,6 +255,7 @@
Loading
254 | 255 | squish = TRUE, |
|
255 | 256 | css_files = c(), |
|
256 | 257 | include_css = c("rmd", "bootstrap", "highlight"), |
|
258 | + | language = FALSE, |
|
257 | 259 | interpolate = TRUE, |
|
258 | 260 | .open = "{{", |
|
259 | 261 | .close = "}}", |
@@ -311,7 +313,8 @@
Loading
311 | 313 | params, |
|
312 | 314 | squish, |
|
313 | 315 | list(extra = read_text(css_files)), |
|
314 | - | include_css |
|
316 | + | include_css, |
|
317 | + | language |
|
315 | 318 | ) |
|
316 | 319 | ||
317 | 320 | msg <- append(msg, body) |
@@ -0,0 +1,31 @@
Loading
1 | + | #' Specify content language |
|
2 | + | #' |
|
3 | + | #' Implements \href{https://datatracker.ietf.org/doc/html/rfc3282}{RFC 3282}. |
|
4 | + | #' |
|
5 | + | #' @noRd |
|
6 | + | content_language <- function(language, content) { |
|
7 | + | if (is.na(language)) language <- FALSE |
|
8 | + | ||
9 | + | if (is.logical(language)) { |
|
10 | + | if (language) { |
|
11 | + | # Auto-detect language. |
|
12 | + | if (requireNamespace("cld3", quietly = TRUE)) { # nocov start |
|
13 | + | detect_language <- cld3::detect_language |
|
14 | + | } else if (requireNamespace("cld2", quietly = TRUE)) { |
|
15 | + | detect_language <- cld2::detect_language |
|
16 | + | } else { |
|
17 | + | stop("Unable to auto-detect language. Install {cld3} or {cld2}.") |
|
18 | + | } # nocov end |
|
19 | + | ||
20 | + | language <- detect_language(content) |
|
21 | + | } else { |
|
22 | + | # Don't include Content-Language. |
|
23 | + | return(NULL) |
|
24 | + | } |
|
25 | + | } else { |
|
26 | + | if (!is.character(language)) { |
|
27 | + | stop("Language must either be a string or TRUE/FALSE.") # nocov |
|
28 | + | } |
|
29 | + | } |
|
30 | + | new_header("Content-Language", paste(language, collapse = ", ")) |
|
31 | + | } |
Files | Coverage |
---|---|
R | 99.84% |
Project Totals (18 files) | 99.84% |
1350887717
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.