Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark result of citeproc conversion as UTF-8 #2202

Merged
merged 5 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 2.10.2
Version: 2.10.3
Authors@R: c(
person("JJ", "Allaire", role = "aut", email = "[email protected]"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ rmarkdown 2.11

- It is possible to specify the version of jQuery via a global option now, e.g., `options(rmarkdown.jquery.version = 2)` (note that the default major version is `3`). This is mainly for advanced users and developers to test different versions of jQuery.

- `pandoc_citeproc_convert()` now handles correctly bib file containing specific UTF-8 characters on non default UTF-8 systems like Windows (thanks, @mitchelloharawild, #2195).


rmarkdown 2.10
================================================================================
Expand Down
2 changes: 2 additions & 0 deletions R/pandoc.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ pandoc_citeproc_convert <- function(file, type = c("list", "json", "yaml")) {
stop("Error ", status, " occurred building shared library.")
}

Encoding(result) <- "UTF-8"

# convert the output if requested
if (type == "list") {
jsonlite::fromJSON(result, simplifyVector = FALSE)
Expand Down
49 changes: 49 additions & 0 deletions tests/testthat/_snaps/pandoc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Converting bib file is working

list(list(author = list(list(family = "Conceição", given = "Sérgio")),
"container-title" = "Portuguese History", id = "conc2021",
issue = "1", issued = list("date-parts" = list(list(2021L))),
title = "História da habitação", type = "article-journal"))

---

[1] "["
[2] " {"
[3] " \"author\": ["
[4] " {"
[5] " \"family\": \"Conceição\","
[6] " \"given\": \"Sérgio\""
[7] " }"
[8] " ],"
[9] " \"container-title\": \"Portuguese History\","
[10] " \"id\": \"conc2021\","
[11] " \"issue\": \"1\","
[12] " \"issued\": {"
[13] " \"date-parts\": ["
[14] " ["
[15] " 2021"
[16] " ]"
[17] " ]"
[18] " },"
[19] " \"title\": \"História da habitação\","
[20] " \"type\": \"article-journal\""
[21] " }"
[22] "]"

---

[1] "---"
[2] "nocite: \"[@*]\""
[3] "references:"
[4] "- author:"
[5] " - family: Conceição"
[6] " given: Sérgio"
[7] " container-title: Portuguese History"
[8] " id: conc2021"
[9] " issue: 1"
[10] " issued: 2021"
[11] " title: História da habitação"
[12] " type: article-journal"
[13] "---"
[14] ""

7 changes: 7 additions & 0 deletions tests/testthat/resources/UTF8.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@article{conc2021,
title={História da Habitação},
author={Conceição, Sérgio},
journal={Portuguese History},
number={1},
year={2021}
}
11 changes: 11 additions & 0 deletions tests/testthat/test-pandoc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TODO: to remove when switching the package to edition 3
local_edition(3)

test_that("Converting bib file is working", {
skip_on_cran()
skip_if_not_pandoc("2.11") # only test with newer Pandoc citeproc
bib_file <- test_path("resources/UTF8.bib")
expect_snapshot_value(pandoc_citeproc_convert(bib_file, "list"), style = "deparse")
expect_snapshot_output(pandoc_citeproc_convert(bib_file, "json"))
expect_snapshot_output(pandoc_citeproc_convert(bib_file, "yaml"))
})