Вопрос

I have been saving some example R markdown html output to Word using pandoc. I actually only do this so I can add some page breaks for easier printing:

system("pandoc -s Exercise1.html -o Exercise1.docx")

Although the output is acceptable I was wondering if there is a way to keep the original syntax highlighting of the R chunks (just as they are in the original knit HTML document)?

Also, I seem to be loosing all images in the conversion process and have to stick them into Word by hand. Is that normal?

Это было полезно?

Решение

Using the rmarkdown package (baked into RStudio Version 0.98.682, the current preview release) it's very simple to convert Rmd to docx, and code highlighting is included in the docx file.

You just need to include this at the top of your markdown text:

---
title: "Untitled" # obviously you can change this
output: word_document # specifies docx output
---

However, it seems that page breaks are still not supported in this conversion.

Другие советы

Why not convert the markdown directly to Word format?

Anyway, Pandoc does not support syntax highlighting in Word: "Currently, the only output formats that uses this information are HTML and LaTeX."

About the images: the Word file would definitely include those if you'd convert the markdown to Word directly. I am not sure about the HTML source, but I suppose you might have a path issue.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top