Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #382 document word report template #1065

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/qualification-ddi.R
Original file line number Diff line number Diff line change
@@ -636,7 +636,7 @@ ddiPKRatioColumnName <- list(

#' @title getGuestDeltaFromConfigurationPlan
#' @description Get Guest et al. delta values for a DDI Ratio plot from the configuration plan
#' @param ddiRatioPlan Properties defined in `DDIRatioPlots` field of confiuration plan
#' @param ddiRatioPlan Properties defined in `DDIRatioPlots` field of configuration plan
#' @return A named list of Guest et al. values
#' @keywords internal
getGuestDeltaFromConfigurationPlan <- function(ddiRatioPlan) {
64 changes: 37 additions & 27 deletions R/utilities-writing-report.R
Original file line number Diff line number Diff line change
@@ -221,6 +221,16 @@ renderWordReport <- function(fileName, intro = NULL, createWordReport = FALSE, w
# Issue #968 Subscript and superscript rendering
lineContent <- gsub(pattern = "<sup>|</sup>", replacement = "^", lineContent)
lineContent <- gsub(pattern = "<sub>|</sub>", replacement = "~", lineContent)
# Expose openxml translations for users
# Manual page break
lineContent <- gsub(pattern = "<pagebreak>", replacement = '<w:p><w:r><w:br w:type="page"/></w:r>`{=openxml}', lineContent)
# Alignment
lineContent <- gsub(pattern = "</div>", replacement = '', lineContent)
lineContent <- gsub(pattern = '<div align=\"right\">', replacement = '`<w:pPr><w:jc w:val="right"/></w:pPr>`{=openxml}', lineContent)
lineContent <- gsub(pattern = '<div align=\"left\">', replacement = '`<w:pPr><w:jc w:val="left"/></w:pPr>`{=openxml}', lineContent)
lineContent <- gsub(pattern = '<div align=\"center\">', replacement = '`<w:pPr><w:jc w:val="center"/></w:pPr>`{=openxml}', lineContent)
lineContent <- gsub(pattern = '<div align=\"justify\">', replacement = '`<w:pPr><w:jc w:val="both"/></w:pPr>`{=openxml}', lineContent)

Comment on lines +228 to +233
Copy link
Member

@Yuri05 Yuri05 Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pchelle
As far as I can see, if I have something like <div align="center"> Tralala </div> it will be replaced by
<w:pPr><w:jc w:val="center"/></w:pPr>{=openxml} Tralala
Does the open xml setting then apply for the rest of the line (and the next line is not affected)?

If I have a table with the div setting in every cell - will the openxml setting then be applied just to the cell?

<div align="center"> Header</div> <div align="center">Header </div>
<div align="left">Cell </div> <div align="left"> Cell </div>
<div align="left">Cell</div> <div align="left"> Cell </div>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both inline and block openxml <w:pPr><w:jc w:val="center"/></w:pPr> only center the next line(s) as long as they are in the same paragraph.

|**C_max**                        |Number |Ratio [%] |
|:----------------------------|:------|:---------|
|Points total                 |`<w:pPr><w:jc w:val="right"/></w:pPr>`{=openxml} 2      |-        |
|Points within Guest *et al.* |`<w:pPr><w:jc w:val="center"/></w:pPr>`{=openxml} 0      |0         |
|Points within 2 fold         |`<w:pPr><w:jc w:val="left"/></w:pPr>`{=openxml}2      |100       |

converts into

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Didn't expect so much intelligence from openXML :)

# When finding a line referencing a table or figure tag as first element
# The new content to write in the word report is
# - previous content = wordFileContent
@@ -229,38 +239,38 @@ renderWordReport <- function(fileName, intro = NULL, createWordReport = FALSE, w
# - next content (caption & table/figure)
# Since the identification is based on the html tag,
# caption on top or below the artifact should stay at the same position
isArtifactReference <- all(
isIncluded(firstElement, "<a"),
any(
bookmarkLines <- NULL
if(isIncluded(firstElement, "<a")){
# Bookmark that uses anchor name (e.g. figure-1-1)
# Used the following website as sample for the code
# https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.bookmarkstart?view=openxml-2.8.1#remarks
bookmarkLines <- c(
"```{=openxml}",
paste0(
'<w:p><w:r><w:bookmarkStart w:id="', anchorName, '" w:name="', anchorName, '"/>',
'<w:bookmarkEnd w:id="', anchorName, '"/></w:r></w:p>'
),
"```"
)

isArtifact <- any(
grepl(pattern = "table", x = anchorName),
grepl(pattern = "figure", x = anchorName)
)
)
bookmarkLines <- c(
"",
"```{=openxml}",
paste0(
"<w:p><w:r>",
if(isArtifact){
# Page break using source code
# https://pandoc.org/MANUAL.html#extension-raw_attribute
'<w:br w:type="page"/>',
"</w:r><w:r>",
# Bookmark that uses anchor name (e.g. figure-1-1)
# Used the following website as sample for the code
# https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.bookmarkstart?view=openxml-2.8.1#remarks
'<w:bookmarkStart w:id="', anchorName, '" w:name="', anchorName, '"/>',
'<w:bookmarkEnd w:id="', anchorName, '"/>',
"</w:r></w:p>"
),
"```",
""
)
wordFileContent <- c(
wordFileContent,
# Add page break and bookmark if artifact is found
bookmarkLines[isArtifactReference],
lineContent
)
bookmarkLines <- c(
"```{=openxml}",
'<w:p><w:r><w:br w:type="page"/></w:r></w:p>',
"```",
"",
bookmarkLines
)
}
}

wordFileContent <- c(wordFileContent, lineContent, bookmarkLines)
}

usedFilesFileName <- sub(pattern = ".md", replacement = "-usedFiles.txt", fileName)
3 changes: 2 additions & 1 deletion docs/dev/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added docs/dev/articles/figures/reference-docx.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file added docs/dev/articles/figures/template-styling.mp4
Binary file not shown.
5 changes: 4 additions & 1 deletion docs/dev/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading