How do I keep title & subtitle when using pandoc to convert .docx to .md in R?

二次信任 提交于 2020-02-04 22:58:36

问题


I'm downloading a Google Doc as .docx and then converting to markdown for manipulation and export to multiple formats.

Problem: When I convert using pandoc, it strips title (and subtitle) and does not add any YAML header information. I could add title manually in the header, but I need it to be scripted, so need to not lose the title (ideally) or extract title from docx and add to YAML header, which would then be concatenated to the converted markdown file.

Example Code, where title is lost on conversion from docx to markdown:

require(rmarkdown);require(devtools)
examplefile=paste0(tempdir(),"/example.docx")
download.file("https://file-examples.com/wp-content/uploads/2017/02/file-sample_100kB.docx",destfile=examplefile)
pandoc_convert(examplefile,to="markdown",output = "example.rmd", options=c("--extract-media=."))

render(paste0(tempdir(), "/example.rmd"),"html_document")
browseURL(paste0(tempdir(),"/example.html"))

来源:https://stackoverflow.com/questions/59652509/how-do-i-keep-title-subtitle-when-using-pandoc-to-convert-docx-to-md-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!