Skip to content

Commit

Permalink
fix: print to console method
Browse files Browse the repository at this point in the history
- if doc is empty, don't display content

fix #463
  • Loading branch information
davidgohel committed Jan 5, 2023
1 parent ae4bc8e commit 59084ff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: officer
Type: Package
Title: Manipulation of Microsoft Word and PowerPoint Documents
Version: 0.5.1.012
Version: 0.5.1.013
Authors@R: c(
person("David", "Gohel", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
10 changes: 7 additions & 3 deletions R/read_docx.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ print.rdocx <- function(x, target = NULL, ...){
names(style_sample) <- style_names$style_name
print(style_sample)

cursor_elt <- docx_current_block_xml(x)
cat("\n* Content at cursor location:\n")
print(node_content(cursor_elt, x))
if (length(read_docx()) > 1) {

This comment has been minimized.

Copy link
@hongyuanjia

hongyuanjia Jan 5, 2023

Contributor

Hi, isn't this will force parsing the template docx every time print is called?

This comment has been minimized.

Copy link
@hongyuanjia

hongyuanjia Jan 5, 2023

Contributor

Hi, isn't this will force parsing the template docx every time print is called?

I think length(x) > 1 is enough

This comment has been minimized.

Copy link
@davidgohel

davidgohel Jan 5, 2023

Author Owner

fixed thanks

This comment has been minimized.

Copy link
@hongyuanjia

hongyuanjia Jan 5, 2023

Contributor

Great!

cursor_elt <- docx_current_block_xml(x)
cat("\n* Content at cursor location:\n")
print(node_content(cursor_elt, x))
} else {
cat("\n* empty document\n")
}
return(invisible())
}

Expand Down
Binary file modified tests/testthat/_snaps/docx-add/body_add-elements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/docx-add/docx-elements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 59084ff

Please sign in to comment.