Skip to content

Commit 72ff761

Browse files
authored
fix: handle citation with square brackets better (#79)
1 parent d908e3f commit 72ff761

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

R/translate.R

+2
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ protect_squaries <- function(node) {
407407

408408
# https://rstudio.github.io/visual-markdown-editing/citations.html#inserting-citations
409409
at_things <- regmatches(text, gregexpr("@[[:alnum:]\\-\\_\\:\\.\\#\\$\\%\\&\\-\\+\\?\\<\\>\\~\\/]*", text))[[1]]
410+
# https://github.com/ropensci-review-tools/babeldown/issues/78
411+
at_things <- sub("</squary><text>", "", at_things)
410412

411413
footnote_things <- regmatches(text, gregexpr("\\^[[:alnum:]]*", text))[[1]]
412414
text <- purrr::reduce(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"translations": [
3+
{
4+
"detected_source_language": "EN",
5+
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n<document xmlns=\"http://commonmark.org/xml/1.0\">\n <paragraph>\n <text xml:space=\"preserve\">\n <text xml:space=\"preserve\">Wickham dice bla <\/text>\n <squary>@wickham24<\/squary>\n <text>.<\/text>\n <\/text>\n <\/paragraph>\n<\/document>\n"
6+
}
7+
]
8+
}

tests/testthat/test-translate.R

+8
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ test_that("deepl_translate() handles square brackets stuff well", {
203203
expect_match(lines, "\\[-@wickham\\+2015\\#]")
204204
expect_match(lines, "también")
205205
})
206+
with_mock_dir("example-square2", {
207+
lines <- deepl_translate_markdown_string(
208+
"Wickham says blah [@wickham24].",
209+
source_lang = "en",
210+
target_lang = "es"
211+
)
212+
expect_match(lines, "\\[@wickham24]")
213+
})
206214
})
207215

208216
test_that("deepl_translate() handles equations well", {

0 commit comments

Comments
 (0)