【问题标题】:Export specific sections in pandoc when converting from Markdown从 Markdown 转换时导出 pandoc 中的特定部分
【发布时间】:2015-08-11 10:02:14
【问题描述】:

我有一个使用Knitr(文学编程)生成的 Markdown 文档。此降价文档使用pandoc 转换为 Microsoft Word (docx) 和 HTML。现在我想在 HTML 中包含 Markdown 中的特定部分,在 docx 中包含其他部分。具体用例是我能够使用rCharts 生成 JS+HTML 图表,这对于 HTML 来说很好,但显然不会在 docx 中呈现,所以在这种情况下我想使用一个简单的 PNG 图像。 我可以为此使用一些特定的 pandoc 语法或技巧吗?

【问题讨论】:

    标签: export knitr pandoc rcharts


    【解决方案1】:

    所以解决这个问题的一种方法是对 knitr 生成的降价进行后处理。

    我输出一些 mustasche,然后使用 R 包 whisker 对其进行解析。

    代码大致如下:

    md <- knit(rmd, envir=e)
    
    docx.temp <- tempfile()
    html.temp <- tempfile()
    
    writeLines(whisker.render(readLines(md), list(html=T)), html.temp)
    writeLines(whisker.render(readLines(md), list(html=F)), docx.temp)
    
    docx <- pandoc(docx.temp, format="docx")
    html <- pandoc(html.temp, format="html")
    
    file.copy(docx, "./report.docx", overwrite=T)
    file.copy(html, "./report.html", overwrite=T)
    

    Rmd (knitr) 包含的内容大致类似于

    {{^html}}
    ```{r}
    WITHOUT HTML
    ```
    {{/html}}
    
    {{#html}}
    ```{r}
    WITH HTML
    ```
    {{/html}}
    

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      • 2020-05-04
      • 1970-01-01
      相关资源
      最近更新 更多