From 93f0f39dd50629ba660163d7a7d7856754d066a0 Mon Sep 17 00:00:00 2001 From: David Gohel Date: Sun, 4 Aug 2024 23:51:58 +0200 Subject: [PATCH] fix: broken internal links in PDF file fix #632 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/runs_as_functions.R | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c0993844..2a360529 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: flextable Title: Functions for Tabular Reporting -Version: 0.9.7.004 +Version: 0.9.7.005 Authors@R: c( person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")), person("ArData", role = "cph"), diff --git a/NEWS.md b/NEWS.md index a2bc4b4b..4270949f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ - fix caption issue that came with no version of bookdown (issue #645), 'bookdown' management of caption has been simplified. - fix vertical overlapping lines with grid output (issue #644) +- fix broken internal links in PDF file, probably due to a change in knitr or +rmarkdown (issue #632) # flextable 0.9.6 diff --git a/R/runs_as_functions.R b/R/runs_as_functions.R index e6822d52..16df89d5 100644 --- a/R/runs_as_functions.R +++ b/R/runs_as_functions.R @@ -164,7 +164,8 @@ runs_as_latex <- function(x, chunk_data = information_data_chunk(x), ls_df = NUL dat[runs_types_lst$is_text == TRUE, c("txt") := list(sanitize_latex_str(.SD$txt))] dat[runs_types_lst$is_equation == TRUE, c("txt") := list(paste0("$", .SD$eq_data, "$"))] - dat[runs_types_lst$is_hlink, c("txt") := list(paste0("\\href{", sanitize_latex_str(.SD$url), "}{", .SD$txt, "}"))] + dat[runs_types_lst$is_hlink & grepl("^#", dat$url), c("txt") := list(paste0("\\hyperref[", gsub("^#", "", .SD$url), "]{", .SD$txt, "}"))] + dat[runs_types_lst$is_hlink & !grepl("^#", dat$url), c("txt") := list(paste0("\\href{", sanitize_latex_str(.SD$url), "}{", .SD$txt, "}"))] dat[runs_types_lst$is_raster == TRUE, c("txt", "left", "right") := list(img_to_latex(.SD$img_data, .SD$width, .SD$height), "", "")] dat[runs_types_lst$is_word_field == TRUE, c("left", "right", "txt") := list("", "", "")] dat[runs_types_lst$is_soft_return == TRUE, c("txt") := list("\\linebreak ")]