Skip to content

Commit 8ac5b36

Browse files
committed
fix: remove relationships in sanitize_images()
fix #708
1 parent 28f13e1 commit 8ac5b36

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: officer
33
Title: Manipulation of Microsoft Word and PowerPoint Documents
4-
Version: 0.7.3.002
4+
Version: 0.7.3.003
55
Authors@R: c(
66
person("David", "Gohel", , "david.gohel@ardata.fr", role = c("aut", "cre")),
77
person("Stefan", "Moog", , "moogs@gmx.de", role = "aut"),

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- fix feed_from_xml for 'officedown'.
66
- `remove_field` argument of function `docx_summary()` now work as expected.
7+
- also remove relationships in `sanitize_images()` (#708).
78

89
# officer 0.7.2
910

R/post-proc.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ sanitize_images <- function(x, warn_user = TRUE) {
254254
file.path(base_doc, setdiff(existing_img, image_files)),
255255
force = TRUE
256256
)
257+
258+
# these iterations will remove removed images from relationships
259+
for (doc_part in all_docs) {
260+
rel <- doc_part$relationship()
261+
rel_data <- rel$get_data()
262+
rel_data <- rel_data[basename(rel_data$type) %in% "image",]
263+
rel_data <- rel_data[!file.exists(file.path(base_doc, rel_data$target)),]
264+
if (nrow(rel_data) > 0) {
265+
rel$remove(rel_data$target)
266+
doc_part$save()
267+
}
268+
}
257269
} else if (inherits(x, "rpptx")) {
258270

259271
rel_files <- list.files(

0 commit comments

Comments
 (0)