1

如何在 RMD 到 DOCx 的表格单元格内渲染 openxml 块?我只是在表格中得到相同的 openxml 文本(mdt)而不是内容..

请问有什么建议吗?

xml_test.RMD:

更新了测试 RMD 代码:

    ---
output:
  word_document:
    reference_docx: ./template.docx
    keep_md: yes
    md_extensions: +raw_tex
editor_options:
  chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

```{r, setuplib, include=FALSE}
#library(tidyverse)
library(knitr)
#library(rmarkdown)
#library(dplyr)
#library(stringr)
library(huxtable)
library(kableExtra)
#library(ftExtra)

```


```{r, xml-test, echo=FALSE, collapse = FALSE}

# XML CONTENT
text_xml <- "<w:p><w:r><w:t>Example text.</w:t></w:r></w:p>"

sanitize(text_xml, type = "rtf")

knitr::asis_output(" \n")

sanitize(text_xml, type = "html")

knitr::asis_output(" \n")

#sanitize(text_xml, type = "latex")

#knitr::asis_output(" \n")

#to_ht <- c(knitr::asis_output(mdt), knitr::asis_output(mdt))
to_ht <- c(text_xml)

#ht <- huxtable::as_hux(to_ht, add_colnames = TRUE, add_rownames = TRUE, escape_contents=FALSE, autoformat = FALSE)
ht <- huxtable::as_hux(text_xml, add_colnames = FALSE, add_rownames = FALSE, escape_contents=FALSE, autoformat = FALSE)

#markdown(ht) <- TRUE
#ht <- set_markdown(ht)

# BAD XML OUTPUT INSIDE CELLS
theme_grey(ht)
knitr::asis_output(" \n")


#knitr::asis_output(ht)
knitr::asis_output(" \n")

# NORMAL XML OUTPUT  HERE:
knitr::asis_output(as.character(text_xml))


```

我发现as_hux()在“ <w:p><w:r><w:t>Example text.</w:t></w:r></w:p> ”中有不正确的清理文本md 中的 RAW 或 WORD: “ <w:p><w:r><w:t>示例文本。</w:t></w:r></w:p>

结果我在 WORD huxtable 单元格中出现了错误输出的问题

问题:我怎样才能避免在 MD 文件中进行这种转换?

4

0 回答 0