diff --git a/NEWS.md b/NEWS.md index f63bec9..cf49e30 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # plume (development version) +* `$get_author_list(suffix =)` is now slightly more flexible and will try less hard to sanitise author list suffixes (#90). + * `PlumeQuarto` no longer converts roles to lower case (#88). * `PlumeQuarto` now supports authors' `degrees` field and the `group` affiliation property (#53). diff --git a/R/als.R b/R/als.R index bf3f581..053b714 100644 --- a/R/als.R +++ b/R/als.R @@ -38,25 +38,23 @@ als_parse <- function(format) { } als_join <- function(x, marks) { + prev_item <- vector("character", 1L) out <- map2_vec(x, marks, \(item, mark) { - if (is_blank(item) && str_contain(mark, "^")) { + if (is_empty(item) && str_contain(mark, "^")) { return("^") } - if (is_blank(item)) { + if (is_empty(item)) { return(item) } + if (is_empty(prev_item) && str_contain(mark, ",")) { + mark <- stringr::str_remove(mark, fixed(",")) + } + prev_item <<- item paste0(mark, item) }) collapse(out) } -als_clean <- function(x) { - for (pattern in c("(?<=^|\\^),|,$", "\\^{2}")) { - x <- str_remove_all(x, pattern) - } - x -} - als_make <- function(data, cols, format) { rows <- itemise_rows(data, cols) marks <- als_parse(format) @@ -65,5 +63,5 @@ als_make <- function(data, cols, format) { } out <- map_vec(rows, \(row) als_join(row, marks$heads)) out <- paste0(out, marks$tail) - als_clean(out) + als_sanitise(out) } diff --git a/tests/testthat/test-get-author-list.R b/tests/testthat/test-get-author-list.R index 3c2576c..0fa2eaa 100644 --- a/tests/testthat/test-get-author-list.R +++ b/tests/testthat/test-get-author-list.R @@ -55,15 +55,15 @@ test_that("get_author_list() returns author list", { aut$get_author_list("^a,^c"), affix_to_authors("^", .a, .seps, "^", .c) ) + expect_equal( + aut$get_author_list("c^,a^"), + affix_to_authors(.c, "^", .seps, .a, "^") + ) expect_equal( aut$get_author_list("a,,c"), affix_to_authors(.a, .seps, .c) ) - expect_equal( - aut$get_author_list(",ac,"), - affix_to_authors(.a, .c) - ) expect_equal( aut$get_author_list("^^ac^^"), affix_to_authors("^", .a, .c, "^")