Skip to content

Commit

Permalink
to_yaml() outputs verbatim true/false (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudgallou committed Mar 28, 2023
1 parent 35b8093 commit be15287
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# plume (development version)

## Bug fixes

* `to_yaml()` now outputs verbatim `true`/`false` (#1).
12 changes: 11 additions & 1 deletion R/yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ separate_yaml_header <- function(text) {
stringr::str_split(text, "(?:^|\\R)-{3}(?:\\R|$)")[[1]]
}

as_verbatim_lgl <- function(x) {
x <- if_else(x, "true", "false")
structure(x, class = "verbatim")
}

yaml_inject <- function(lines, replacement) {
if (length(lines) < 3L) {
abort_input_check(msg = c(
Expand All @@ -36,7 +41,12 @@ yaml_inject <- function(lines, replacement) {
))
}
line_break <- line_break()
yaml <- as.yaml(replacement, line.sep = line_break, indent.mapping.sequence = TRUE)
yaml <- as.yaml(
replacement,
line.sep = line_break,
indent.mapping.sequence = TRUE,
handlers = list(logical = as_verbatim_lgl)
)
out <- replace(lines, 2, yaml)
paste0(out, collapse = paste0("---", line_break))
}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ aut$to_yaml("file.qmd")
number: 00 00 00 01
note: born in 1713 in Langres
attribute:
corresponding: yes
corresponding: true
affiliations:
- ref: aff1
- id: aut2
Expand All @@ -101,7 +101,7 @@ aut$to_yaml("file.qmd")
family: Rousseau
email: [email protected]
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff2
- id: aut3
Expand All @@ -111,7 +111,7 @@ aut$to_yaml("file.qmd")
email: [email protected]
note: also known as Voltaire
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff2
- id: aut4
Expand All @@ -121,7 +121,7 @@ aut$to_yaml("file.qmd")
email: [email protected]
note: born in 1717 in Paris
attribute:
corresponding: yes
corresponding: true
affiliations:
- ref: aff1
- ref: aff3
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/yaml-headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author:
number: '00'
note: a
attribute:
corresponding: yes
corresponding: true
affiliations:
- ref: aff1
- ref: aff2
Expand All @@ -19,7 +19,7 @@ author:
family: Zz
email: [email protected]
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff3
- id: aut3
Expand All @@ -29,7 +29,7 @@ author:
email: [email protected]
note: b
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff1
- ref: aff4
Expand Down Expand Up @@ -59,7 +59,7 @@ author:
family: Zz
email: [email protected]
attribute:
corresponding: yes
corresponding: true
affiliations:
- ref: aff1
- id: aut2
Expand All @@ -69,7 +69,7 @@ author:
email: [email protected]
note: b
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff2
- ref: aff3
Expand All @@ -81,7 +81,7 @@ author:
number: '00'
note: a
attribute:
corresponding: no
corresponding: false
affiliations:
- ref: aff3
- ref: aff4
Expand Down

0 comments on commit be15287

Please sign in to comment.